in reply to Having Access to a file two times
seek, or close and re-open the file. ...or make your filehandle lexically scoped to a block just outside your while loop (which will handle closing your file for you). In other words:
{ open my $fh, '<', $filename or die $! while ( <$fh> ) { # do your stuff. } # Note, your $fh is about to pass out of scope, which # will close the filehandle in cleanup. } { $open my $fh, '<', $filename or die $! while ( <$fh> ) { # do your other stuff. } } # Now the second filehandle fell out of scope and closed too.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Having Access to a file two times
by sesemin (Beadle) on Sep 21, 2008 at 07:16 UTC | |
by AnomalousMonk (Archbishop) on Sep 21, 2008 at 08:31 UTC | |
by oxone (Friar) on Sep 21, 2008 at 10:00 UTC | |
by jwkrahn (Abbot) on Sep 21, 2008 at 11:22 UTC | |
by AnomalousMonk (Archbishop) on Sep 21, 2008 at 22:11 UTC |