Think about Loose Coupling | |
PerlMonks |
Re: Re: while(<>) { ... } considered harmfulby Ovid (Cardinal) |
on Sep 08, 2002 at 00:58 UTC ( [id://195948]=note: print w/replies, xml ) | Need Help?? |
Unless I totally misunderstood the above comments -- which is possible as I just briefly skimmed them -- the problem here is not that map and grep don't localize $_, but that they may execute code that may alter the value of $_, which in this case is aliased to a constant. Consider this code:
That code will print 'Ovid' because $_ has been localized within the map statement. Now, if you try to alter the $_, your code fails because you're trying to alter a constant:
To get around that, you can do this:
That allows you to assign the aliased constant to a real variable, thus avoiding the problems outlined in this thread. Cheers, Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In Section
Meditations
|
|