October 30th, 2005

belize

Fun bug

Here's a fun bug. See if you can find what's happening:
my @data = function();
my @sorted = sort { $a->method <=> $b->method } @data;

foreach my $item (@sorted) {
    $item->other_method;
}

The error message I was getting:

Can't call method "other_method" on undefined value at line ...

The question to you is: how is that possible?

I think you'll smile if/when you realize the answer.