Re: Error puzzler
Uri Guttman <[email protected]> Wed, 13 Sep 2006 14:12:30 -0400
| Newsgroups | gmane.comp.lang.perl.fun |
|---|---|
| Message-ID | <[email protected]> |
>>>>> "PS" == Peter Scott <[email protected]> writes: PS> Here's a distillation of something that just bit me, behaves the same on PS> 5.6.1 and 5.8.5. Observe the following program: PS> for (1..2) { PS> print_file($0); PS> } PS> for (qw(one two)) { PS> print_file($0); PS> } PS> sub print_file { PS> local @ARGV = shift; PS> while (<>) { print } PS> } PS> __END__ PS> Before running it, can you tell: PS> Will it succeed or not? PS> If not, with what error? PS> Where? PS> Why? i haven't run it but i already see conflicts with nested $_. the while(<>) will use $_ and so do the for loops. i wouldn't hazard a guess as to what the code will do. i never run into that since i rarely use $_. i use my vars on all loops and only use $_ where required (map/grep/for modifier) or in one liners and such. uri -- Uri Guttman ------ [email protected] -------- http://www.stemsystems.com --Perl Consulting, Stem Development, Systems Architecture, Design and Coding- Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org