in reply to Re^2: Canon concerning coderef calls?
in thread Canon concerning coderef calls?
Chromatic's OO way
I wouldn't really call that an OO way. Sure, it uses can as a class method on main, but that's where the OOishness ends. It returns a plain coderef and executes it with a different dereferencing syntax than you used. I believe it is also the only alternative that does not use a symbolic reference.
To reinforce the point about being a plain coderef, this works:
foreach (@list) { my $coderef = main->can($_); &$coderef($_); }
And this does too, if you really want to get rid of all the pointy arrows:
foreach (@list) { my $coderef = UNIVERSAL::can('main', $_); &$coderef($_); }
Update: and if you want to see what I would consider the "OO way":
foreach (@list) { main->$_($_); }
But, frankly, I think that's very ugly. It uses a symbolic reference too. I would use can as chromatic originally did.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Canon concerning coderef calls?
by NetWallah (Canon) on Nov 16, 2004 at 03:28 UTC | |
by revdiablo (Prior) on Nov 16, 2004 at 06:06 UTC |