March 2011 Archives

Bench: a simpler benchmark module

There was a post in or Planet Perl Iron Man (sorry, forgot the exact article) that said something along the line of: "Benchmark is a fine module, but for simplicity I'll use the time command". Which immediately hit home with me, because I too very seldomly use Benchmark. I guess the problem is I almost always have to perldoc it before using it, and there are quite some extra characters to type.

So last weekend I wrote Bench (/users/steven_haryanto/2011/03/index.html

Yet another stupid mistake #3: local is not that magical

One of my favorite things in Perl is of course local variables, a.k.a. dynamic scoping. After learning that you can localize just a hash pair, or an array element, I have often used local() as sort of a stack to save temporary results. Then a few weeks ago I was hit with a bug:

    local $ary->[-1] = $foo;

which is okay, until I got carried away and shift(), pop(), splice(), et al on @$ary in manipulate_ary(), and expected local() to take care of everything. Of course it's not that magical.

Yet another stupid mistake #2: my oh my

Stricture helps me catch some typos by requiring predeclaration of variables (e.g. using the lexical my()). But it doesn't warn me about my stupidity. In this month alone, I have been bitten by two episodes of sloppy refactoring, where I left an extra 'my' on an inner block, something like:

my $foo = blah();
for (...) {
    my $foo = ...;
    # we lost what we've done to the inner $foo

Of course, -w and 'use strict' didn't help me here. -w only warns about the second 'my' if done in the same scope. And so around half an hour were spent chasing these two sile…


If you're like me, over the years you'll have had your todo lists scattered over multiple programs and places. First a simple text file with homebrewn format, then various Windows programs, then various Linux GUI programs, then back to Notepad and joe/gedit/kate, then various apps on cellphones, then pencil & paper (due to cellphones keep getting lost/stolen), then some cloud apps, then todo.txt, then finally org-mode. And if you're anything like me or many others, you'll find that org-mode is *it*.

I'm now in the (long, bo…

About Steven Haryanto

user-pic A programmer (mostly Perl 5 nowadays).