dragonchild has asked for the wisdom of the Perl Monks concerning the following question:
What I want to do is instead of the two lines in the foreach loop, I want one line. Something like:use strict; use warnings; package Blah; sub new { bless {}, shift } sub Foo { print "Foo\n"; } sub Bar { print "Bar\n"; } package main; my %Movement = ( foo => 'Foo', bar => 'Bar', ); my $foo = Blah->new; foreach my $key (keys %Movement) { my $func = $Movement{$key}; $foo->$func; }
But, that doesn't work. (Otherwise, I wouldn't be posting!) Any thoughts?foreach my $key (keys %Movement) { $foo->$Movement{$key}; }
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Weird function calling...
by robin (Chaplain) on Jan 07, 2002 at 23:25 UTC | |
by merlyn (Sage) on Jan 07, 2002 at 23:31 UTC | |
by robin (Chaplain) on Jan 07, 2002 at 23:42 UTC | |
|
Re: Weird function calling...
by runrig (Abbot) on Jan 07, 2002 at 23:17 UTC | |
|
Re: Weird function calling...
by Netmonger (Initiate) on Jan 09, 2002 at 00:57 UTC | |
by runrig (Abbot) on Jan 09, 2002 at 01:09 UTC |