in reply to Re^2: Making each(@ary) work on 5.10?
in thread Making each(@ary) work on 5.10?
As I said, there's a reason I called it aeach instead of each. You can define your own sub called each, but if you try to actually use it, you just get the Perl built-in. This goes right down to the Perl tokenizer.
There are only three ways to call your own each function: qualify your call with the package name (MyPackage::each(@array)), prefix it with an ampersand (&each(\@array) - note that prototype will be ignored, so you need to pass a reference), or call it as a method (but methods can't be called on unblessed arrays, unless you use autobox).
Now, it is palso ossible to overwrite the core each with your own:
use Tie::ArrayAsHash 'aeach'; BEGIN { *CORE::GLOBAL::each = \&aeach };
However, this is a global override rather than being package scoped or lexically scoped. (You might think that it would introduce infinite recursion because aeach internally calls each, but actually it does not. This is because aeach has already been compiled when the override happens, so is not affected by the override.)
To override each for just a lexical scope is a much harder proposition.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Making each(@ary) work on 5.10?
by sedusedan (Pilgrim) on Jul 27, 2012 at 09:00 UTC | |
by tobyink (Canon) on Jul 27, 2012 at 13:10 UTC | |
by sedusedan (Pilgrim) on Jul 27, 2012 at 14:08 UTC | |
by tobyink (Canon) on Jul 28, 2012 at 09:48 UTC | |
|
Re^4: Making each(@ary) work on 5.10?
by Anonymous Monk on Jul 27, 2012 at 07:44 UTC | |
by tobyink (Canon) on Jul 27, 2012 at 12:36 UTC |