This is a rather amateurish Perl cheat sheet for when you're starting with trigonometry in Perl. First, Perl uses radians instead of degrees, so you'll have to use Math::Trig's rad2deg and deg2rad functions to computer the one or the other, compare Perl Cookbook, ~ chapter 2. Then you might want to calculate the arcsin of […]
In case you are developing web applications in Dancer or similar "first local then online" frameworks one common setup is to use SQLite when you run your app local in development mode, and then you take it online into the production environment where it utilises a MySQL server for the database work. One thing is […]
While developing a Dancer application recently, I started using SQL sentences with a REGEXP filter in them. Which resulted in a strange error... As I found out, SQLite's implementation of the REGEXP function is quite incomplete. Solution for now: Make sure you've got a properly updated DBD::SQLite driver for your DBI. Newer versions have a […]
As a personal reminder, here's the dir layout or directory structure Dancer implicitly recommends by making it what the "make application" switch generates: $ cpan Dancer # or cpanp, or cpanm $ dancer -a MyApp Dancer version ?: + ./MyApp + MyApp/views + MyApp/views/index.tt + MyApp/views/layouts + MyApp/views/layouts/main.tt + MyApp/environments + MyApp/environments/development.yml + MyApp/environments/production.yml + […]
The sitemaps protocol (help at Google, official homepage sitemaps.org) as proposed by Google is gaining wider popularity. When you are running a site and want good visibility in search engines, you surely want to have it crawled regularly and completely. One stepstone into that direction is to serve your content in the form of a […]
When I scan images, or paper notes, I like to leave a short note on the document I scanned referrring to my scanned digital copy of it. For example, when I scanned an image, I note on the back of it that this one is already scanned and I don't have to rescan it over […]
This regular expression here can be used to match YouTube IDs: $youtube_url =~ /watch\?v=([\w-]{11})/; In words: \w: match any alphanumeric chars including _ (the dash), means letters, numbers; also match - (the minus); match eleven chars.It ignores further url query parameters.
Often, you may ask yourself what version of a specific perl cpan module you've got installed on your system. So here is how to find out what version a perl module is, as an example on CGI.pm: perl -e 'use CGI; print $CGI::VERSION."\n"'
Writing applications in Perl with WxPerl for GUI layout is nice. Decorating your apps with images is even nicer. Now when you go the extra mile to package your apps as compiled binaries, it can be regarded as messy to have the used images as external dependencies outside your code. One solution around this is […]
Today I banged my head for a few minutes against a strange error: I got a print() on closed filehandle from a simple code passage: open(my $out,">>", "/some/file") or die "File error: $!"; print $out "sometext\n". close($out); Can you spot the error? After reading through two good help threads here and here, I came to […]
A minute ago I had problems running the cpan install of Crypt::SSLeay under Windows + StrawberryPerl: cpan -i Crypt::SSLeay Before I tried the cpan module install I downloaded and installed openssl and Microsoft Visual C++ 2008 Redistributable Package. When cpan asked me where I installed openssl I pointed it to the right directory, but still […]
Often while debugging nasty "500 Internal Server Errors" and when everything seems to work on command line but the webserver refuses to properly serve your script's output (btw: check if you set permissions right, twice!) you might want to feed the query_string to a script on command line. Running a script in default mode, without […]
Shortly after learning about StrawberryPerl (which I documented in my post about it as replacement for ActivePerl) I was tempted to actually try it. Well, tempted..., more like forced to try it. A script I am developing needed HTTP::Proxy and I was just unable to fetch it/get it working in the ActivePerl environment - even […]
Although the email protocol (RFC2822) is one of the oldest of all the "Internet protocols", getting perl to handle it is actually not that simple at first. Heading over to cpan it took me some minutes and a prototype script to get it do what I thought would be a one-liner. My scenario was that […]
WxPerl (Wx::App on cpan) is a great tool to design visually rich graphical user interfaces for your scripts. But the downside is that the learning curve is quite steep. There were many incident when I was banging my head against the wall for hours until I finally got what I intended. This post is meant […]
Windows and Perl - that's quite a story. For a number of years now I've been using ActivePerl, not without encountering some problems along the way. One of the most annoying is that ActivePerl relies on ppm packages to install modules, not the original CPAN modules. So it takes some time until ppm versions of […]
When starting the coding/design of a new search engine crawler (a challenging task, read What I've learned from writing a large scale search engine), some input from people who've been there and done that might be quite helpful. Of course, there is the original Google paper and some other stuff around that I like to […]
Compiling scripts with pp, PAR's helper script, to executable binaries (.exe files on Win32) should be a pretty straightforward process. Anyway, if you are developing GUI applications, probably with Wx, you will surely run into some problems. Upon execution, the generated execs will complain about missing libraries, DLLs or similar. This is because pp does […]
Getting a working version of Wx and wxperl running on a amd64 Ubuntu system (mine was 6.06 dapper) can be a bit tricky. Everytime I tried to install Wx via cpan the Alien::wxwidgets module complained and refused to install this required package for Wx. The problem seemed be that I had no version of Wx […]
There is a handy short version for a classic if-else-statement that is very useful, but everytime I'd like to use it, I just can't fully remember what its syntax was. And looking it up on google is hard, because "if" is a very common word... It is especially useful on initializing variables in a cgi […]
Recently, I had to wrangle a large dataset, with over 3 million key-value pairs. I needed to iterate over them in a sorted way and I needed the hash-structure to weed out "already-seen-keys". My first approach was to build a hash in memory, with the usual my %hash, then adding keys and values in a […]
A quick reminder: How do I pad a string so that a number or string gets leading zeros? Answer: By using sprintf: my $number = 123; $number = sprintf("%07d", $number); print $number; Output: "0000123" after the %: "0" is the character to add, <number>d is the amount of digits (that's why it's "d") to add. […]
Running MySQL and doing join'ed queries you might run into problems when you try to get results from two tables into one results set, where both tables have a field that is identically named (common with id-fields). For example: SELECT table1.id, table1.fieldA, table1.fieldB, table2.id, table2.fieldC, table2.fieldD FROM `table1`,`table2` WHERE table1.fieldA = 'test' AND table1.id = […]
Writing a large-scale web-crawling and web-indexing search engine from scratch is a large beast to tame and in many cases a project that is heading for desaster right from the start. As you can read in Alex's worklog for the ongoing effort to manage the Majestic-12 distributed search engine, writing a crawler alone can cost […]
In this blog, I'd like to publish trick, tips and hints related to the scripting/programming language Perl, which should not be confused with PEARL. Although the origin of the name Perl are a more adventurous story, today most agree that Perl stands for Practical Extraction and Report Language, which summarises quite well what it does […]
This procedure is useful when your shared hosting webserver is running an outdated version of perl but your applications need a newer version; for example when utf8 functionality is needed which only newer versions fully support. First read this small paragraph: http://www.bugzilla.org/docs/2.22/html/nonroot.html Then get the latest perl sources and extract/configure/compile it: $ wget http://perl.com/CPAN/src/stable.tar.gz $ […]