Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking through GBARR's Error module, and I see:
sub except (&;$) { my $code = shift; my $clauses = shift || {}; my $catch = $clauses->{'catch'} ||= []; my $sub = sub { my $ref; my(@array) = $code->($_[0]); if(@array == 1 && ref($array[0])) { $ref = $array[0]; $ref = [ %$ref ] if(UNIVERSAL::isa($ref,'HASH')); } else { $ref = \@array; } @$ref }; unshift @{$catch}, undef, $code; $clauses; }
What purpose can that anonymous subroutine definition ($sub) possibly be serving, considering that it's not referenced anywhere?

Replies are listed 'Best First'.
Re: Useless code in Error.pm?
by Juerd (Abbot) on Apr 11, 2002 at 08:16 UTC

    unshift @{$catch}, undef, $code;

    Weird. That's not what's in my Error.pm. In my copy, it says:

    unshift @{$catch}, undef, $sub;
    Check if there's a newer version than the one you use. Installed on my box is 0.15.

    Yes, I reinvent wheels.
    

      Yep, I was running 0.13, that was the problem. Thanks!