The "local *_ = \ $scalar" trick makes $_ become an alias to $scalar (really the value in $scalar). This is equivalent to the effect that foreach() has, with the exception that this method does not work for lexical variables.
What do you mean when you say "this method does not work for lexical variables?" It will work just fine as a way to iterate over lexically declared arrays as well as global arrays. There is nothing wrong with using a typeglob to alias a lexical, is there?
I don't think you meant to imply otherwise but that statement confuses me.
$ perl -Mstrict -wle 'my @lexical = (1..3); for (my $i=0; $i<@lexical; + $i++){ local *_ = \$lexical[$i]; $_ = "foo"} print "@lexical"' foo foo foo
Update: Upon re-reading that, I'm guessing that you simply mean that you can't use a lexical as the iterator variable.
-sauoq "My two cents aren't worth a dime.";
In reply to Re: Re: Starting foreach at an arbitrary position
by sauoq
in thread Starting foreach at an arbitrary position
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |