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