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.
In reply to Re^3: Canon concerning coderef calls?
by revdiablo
in thread Canon concerning coderef calls?
by jobi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |