in reply to variable function thingy

What you're looking for is a reference to a sub. You need something like this:

$func_ref = \&post; #this lets func_ref point at a sub call post ... &$func_ref(); #call the sub we've pointed at

Replies are listed 'Best First'.
Re: Re: variable function thingy
by rob_au (Abbot) on Oct 18, 2002 at 02:53 UTC
    This answer is correct, but I would also add that it is possible to store the subroutine name rather than as code reference. For example:

    sub test { print "Hello world!\n"; } my $subroutine = "test"; &{$subroutine};

    The caveat to this approach is that it breaks strict refs unless the $subroutine scalar is evaluated (eg. eval $subroutine).

     

    Update - Check out the nifty example from broquaint in this thread here

     

    perl -e 'print+unpack("N",pack("B32","00000000000000000000000111010010")),"\n"'