Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Canon concerning coderef calls?

by pg (Canon)
on Nov 15, 2004 at 19:23 UTC ( [id://407919]=note: print w/replies, xml ) Need Help??


in reply to Canon concerning coderef calls?

Store the code ref itself, not the names in your list.

use warnings; use strict; my @list = (\&one, \&two, \&three); for (0 .. $#list) { &{$list[$_]}($_); } sub one { my $number = shift; print "Sub $number reporting for duty.\n" } sub two { my $number = shift; print "Sub $number reporting for duty.\n" } sub three { my $number = shift; print "Sub $number reporting for duty.\n" }

Replies are listed 'Best First'.
Re^2: Canon concerning coderef calls?
by jobi (Scribe) on Nov 15, 2004 at 19:51 UTC
    Alas, in the specific project I am working on (not the example code) the list is not for me to create, just to use.

    Still, thank you for your wisdom.
    jobi
Re^2: Canon concerning coderef calls?
by ihb (Deacon) on Nov 17, 2004 at 09:24 UTC

    my @list = (\&one, \&two, \&three);

    my @list = \(&one, &two, &three);
    :-)

    ihb

    See perltoc if you don't know which perldoc to read!
    Read argumentation in its context!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://407919]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-24 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found