jorg has asked for the wisdom of the Perl Monks concerning the following question:
my $foo = Obj->new; for (qw( create init add )) { $foo->$_(); # note -- $foo->$_ will not work, ()'s needed }
This approach works fine as long as you're not passing parameters along.
I want to do something along the lines of :
... but i'm getting Argument "colorspace=>'gray'" isn't numeric in subroutine entry at im.pl line 10.Now this tells me that probably the parameter passing works but it's expecting a numeric parameter and the "qw" garbles it somehow. Is my observation correct?my $method = 'Quantize'; my $parameters = qw (colorspace=>'gray' compression=>'none'); my $image = Image::Magick->new; $image->Read('/share/colortransition.jpg'); $image->${method}($parameters); $image->write(filename=>'/share/graytransition.jpg');
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: dynamic methods with variables
by liz (Monsignor) on Jul 30, 2003 at 12:47 UTC | |
|
Re: dynamic methods with variables
by broquaint (Abbot) on Jul 30, 2003 at 12:48 UTC | |
|
Re: dynamic methods with variables
by jorg (Friar) on Jul 30, 2003 at 13:11 UTC |