Indirect method invocation
- From: lists@xxxxxxxxxxx (Jan Eden)
- Date: Wed, 27 Jul 2005 17:21:16 +0200
Hi,
it does not seem to be possible to use indirect method invocation with anything but a scalar. While this works:
my $mode = $parameters{mode};
$item->$mode();
I cannot seem to find a proper bracketing to make this work:
$item->$parameters{mode}();
Is my assumption correct?
My other problem is that the cookbook quotes (something like) the following code as an example for storing method names:
my %actions = (
display => $item->display(),
move_picture => $item->move_picture($item->{id}, $item->{parameters}->{position}),
commit => $item->commit()
);
Now I thought I could use
$actions{$parameter{mode}};
to invoke the proper method, but I get a "Useless use of hash element in a void context" error.
I can see why I get that error - but why would someone want to build a hash like %actions then, which just maps names to method invocations, without a way to actually get to those method invocations?
In other words, I would like to have something like the %actions hash to construct a more flexible version of the $item->$mode() construct, where I can pass different additional parameters to each method.
Thanks,
Jan
I have known more men destroyed by the desire to have wife and child and to keep them in comfort than I have seen destroyed by drink and harlots. - W.B. Yates
.
- Follow-Ups:
- Re: Indirect method invocation
- From: Xavier Noria
- Re: Indirect method invocation
- From: Jan Eden
- Re: Indirect method invocation
- Prev by Date: RE: Help: automated email forwarding similar to .forward
- Next by Date: login shell?
- Previous by thread: Trying to scape data out of HTML
- Next by thread: Re: Indirect method invocation
- Index(es):