On 04/12/2011 08:26 AM, marcos rebelo wrote:
Hi all
I have a code like:
foreach my $key ( ... ) {
my $sub = "get_$key";
$self->$sub;
...
}
If I can do this, I can also do it without the variable $sub.
What is the syntax? please
Best Regards
Marcos Rebelo
#!/usr/bin/perl
use strict;
use warnings;
no strict 'refs'; # to allow you to use names as references
sub foo { print "Hello, Foo\n"; }
sub bar { print "Hello, Bar\n"; }
sub baz { print "Hello, Baz\n"; }
sub waldo { print "Hello, Waldo\n"; }
sub pepper { print "Hello, Pepper\n"; }
sub salt { print "Hello, Salt\n"; }
sub pork { print "Hello, Pork\n"; }
for my $verb (qw/foo bar baz waldo pepper salt pork/) {
$verb->();
}
--L