That did correct the problem. I don't understand what local $_; did. So a while loop will change $_ if it is inside a foreach loop since both use $_?
-----Original Message----- From: Jenda Krynicky [mailto:[EMAIL PROTECTED] Sent: Thursday, July 10, 2003 12:13 PM To: [EMAIL PROTECTED] Subject: Re: Why is $_ being change. From: "Paul Kraus" <[EMAIL PROTECTED]> > I have two subroutines that are have unexpected results. The first is > passed an array ref to a list of file names. It then calls a > subroutine and passes a file name to that subroutine. When that > routine finishes everything in the @files that was passed to point is > changed from a file name to the relevant line matched by the reg exp > in the subroutine point. All the other files that where in the array > are now empty. > > > sub processdate { > <code snipped> > > foreach ( @files ){ > > if ( /_\((\d+)\)_/ ) { > print "$_\n"; > <code snipped> > } > } > <code snipped> > } > > sub point { > my $filename = shift; > open ( IN, "<$$filename" ) or die "Could not open file $filename > $!\n"; > while ( <IN> ) { > return formatnum( $1, $2 ) if ( /Point Health > Centers\s+((?:\d+,)?(?:\d+\.)?\d+)(-?)/ ); > } > } Just the other day someone asked why does someone localize $_ ... Notice that both loops, the foreach() in processdate() and the while() in point() use the $_. I believe foreach does locaize the variable, but while() does not. Add local $_; into the point() and you should be fine. Jenda ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]