Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How can I call subroutines in an array

by Chmrr (Vicar)
on Jun 10, 2003 at 04:54 UTC ( #264539=note: print w/ replies, xml ) Need Help??


in reply to How can I call subroutines in an array

It's hard to tell, but you're calling them when you think you're putting them into the array -- that is, at the @procs = (&a1, &a2) line. The solution to this problem is references, as discussed in perlref and perlreftut. As follows:

use strict; use warnings; sub a1 { print("a1\n"); } sub a2 { print("a2\n"); } my @procs = (\&a1, \&a2); foreach (@procs) { $_->(); }

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'


Comment on Re: How can I call subroutines in an array
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2015-07-05 13:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls