sicrj has asked for the wisdom of the Perl Monks concerning the following question:
I want to expand a variable name into a call to a subroutine.
Seems doable, but I'm at a loss as of yet.
Info:
perl v5.6.0
Mandrake Linux 7.2 - 2.2.17
What I want:
Based on an argument given, I need to cycle through some number
of subroutines. Example code follows, hopefully it's clear
enough to explain my point:
So, if a user enters ./program.pl 8, I want to go through subroutines 1 through 8. I've also tried calling the subroutines by using:$count = shift; for($runs = 1; $runs <= $count; $runs++){ &func_"$runs"; } sub func_1{} sub func_2{} sub func_3{} # etc, etc, etc.
No luck there either. And, I've tried various combinations of quote marks.func_"$runs"();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 1: Expanding Variable Names in Calls to Subroutines
by tilly (Archbishop) on Jul 11, 2001 at 06:34 UTC | |
|
Re: Expanding Variable Names in Calls to Subroutines
by tachyon (Chancellor) on Jul 11, 2001 at 06:38 UTC | |
|
Re: Expanding Variable Names in Calls to Subroutines
by LD2 (Curate) on Jul 11, 2001 at 06:37 UTC | |
by sicrj (Initiate) on Jul 11, 2001 at 06:49 UTC |