It just so happens that this loop appears inside a subroutine I call a bunch of times. Even between subroutine calls, the iterator for @domain_files is not reset! In short, @domain_files is screwed up. This seems like a pretty serious bug to me. Is this a known shortcoming of Perl? The work-around is to use a for loop with your own iterator:my $domain_file; FILE: foreach (@domain_files) { $domain_file = $_; print "\tLooking in domain file $domain_file\n" if (DEBUG == 2); open DOMAIN_FILE, $domain_file or die "Could not open domain file $domain_file: $!"; while () #! Could use globbing here... { if (m/$aname_regex/) { $aname = $1; print "\tFound A name: $aname in file $domain_file\n" if DEBUG; #There's only one A name for a given host, so #stop checking files... last FILE; #*Trouble! foreach iterator is not reset. } } }
Thanks for any comments you can provide on this. It's a weird one...FILE: for (my $i = 0; $i <= $#domain_files; $i++) { $domain_file = @domain_files[$i]; print "\tLooking in domain file $domain_file\n" if (DEBUG == 2); open DOMAIN_FILE, $domain_file or die "Could not open domain file $domain_file: $!"; while () #! Could use globbing here... { if (m/$aname_regex/) { $aname = $1; print "\tFound A name: $aname in file $domain_file\n" if +DEBUG; last FILE; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: foreach gotcha!
by chromatic (Archbishop) on Sep 22, 2000 at 02:20 UTC | |
|
It was a $_ scoping issue!
by Anonymous Monk on Sep 22, 2000 at 05:00 UTC | |
by merlyn (Sage) on Sep 22, 2000 at 05:17 UTC | |
|
RE: foreach gotcha!
by merlyn (Sage) on Sep 22, 2000 at 01:58 UTC | |
by myocom (Deacon) on Sep 22, 2000 at 02:01 UTC | |
by extremely (Priest) on Sep 22, 2000 at 03:38 UTC |