perl

A 4-post collection

Still Slow After Fork

A simple paradigm for speeding up code is to use multiple processes created by fork. Unfortunately this doesn't always work as we can see in the following example. Calculating Tons of MD5 A simple case would be brute forcing MD5. Using Math::Cartesian::Product it's easy to generate all the 5 letter combinations and calculate an MD5 sum from each of them. If we were searching for the sources of the following MD5s: 5d41402abc4b2a76b9719d911017c592 3899dcbab79f92af727c2190bbd8abc5 9aeaed51f2b0f6680c4ed4b07fb1a83c 96e25e3c6373262faae824dc5a16cce1 We could use the following perl program to brute

Read more

Fixing Legacy Perl Functions With Decorators

Function decorators give us a way to modify a function's behaviour without changing its source. This is useful in changing the behaviour of complex or legacy functions that you don't want to touch. Although perl does not have a built-in syntax for creating or using decorators, typeglob manipulations are used to easily fill the gap. Reasons To Decorate Take the following implementation for fibonacci calculating function: sub fib { my ($n) = @_; print "DEBUG - calculating fib($n)\n"; $n < 2 ? 1 : fib($n-1) + fib(

Read more

Building Web UIs with Perl + Mojolicious

Mojolicious is one of 3 leading web frameworks available in the perl ecosystem (along with Dancer and Catalyst) and by far my favorite. Mojolicious aims to provide a complete web development experience. It thus has no hard dependencies, comes with a built-in development and production server and many other features one needs to build a web application. It's easy to install, has an applciation generator script and many plugins and extensions. The following examples will take you from building a first hello world app in Mojolicious

Read more

Perl Exercises

A short list of exercises I use when teaching perl. Hope you'll find them useful. Feel free to add yours in the comments. Using And Creating References Write a function called diffsum that takes 2 lists and prints the difference in their sum. For example: my @x = (10, 20, 30); my @y = (10, 20, 40); # prints: -10 diffsum(\@x, \@y); Write a function called longer_than that takes a list and a scalar and prints all the strings in lists longer than scalar. Caveat: The scalar

Read more