in reply to call subroutines via hash

You need an explicit arrow operator to dereference (i.e. call) the subroutine.

$dispatch{$input}->()

(Update: First impressions are not always right. Thanks, Eric and Roy for catching my mistake.)

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^2: call subroutines via hash
by Roy Johnson (Monsignor) on Jan 04, 2006 at 21:05 UTC
    Not in recent perls. The arrow-between-brackets-is-optional rule has been extended to sub refs.
    my %thingy; $thingy{foo} = sub { print "Cool!\n" }; $thingy{foo}();

    Caution: Contents may have been coded under pressure.
Re^2: call subroutines via hash
by eric256 (Parson) on Jan 04, 2006 at 21:02 UTC

    Actualy thats not true. I'm not sure why, I thought the same thing until i went to run it. Turns out that part of the code works. ;)


    ___________
    Eric Hodges