Jun 21 2008

Shorthand if-clause

Tag: Uncategorizedtengo @ 7:10 am

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 […]


Jun 17 2008

Working with very large hashes

Tag: Uncategorizedtengo @ 10:59 am

Recently, I had to wrangle a large dataset, with over 3 million key-value pairs. I need 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 giant […]


Jun 01 2008

How to format a string with leading zeros?

Tag: Uncategorizedtengo @ 9:09 am

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. See the documentation for sprintf.