loituma has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I am trying to make a copy of the filehandle, that is *not* sharing file position. I am parsing a big file, and at some point I want to keep a copy for later new parsing. I tried several things, but file positions keep getting shared. Here is an exemple of what I tried :
my $filename = $ARGV[0]; my $nb_lines = 0; open (my $file, $filename) or die "Can't open '$filename': $!"; my $hdl_sauv; while (<$file>) { $nb_lines++ ; if ($nb_lines == 5) { open ($hdl_sauv, "<",$file) || die "cannot open $file\n"; } } my $saved_line = <$hdl_sauv>; print "$saved_line\n";
I want $hdl_sauv to be a pointer to the position 5. This code isn't working, but I don't know how to write it. Any tip? Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to make a copy of filehandle
by LanX (Saint) on Apr 09, 2013 at 08:19 UTC | |
|
Re: How to make a copy of filehandle
by hdb (Monsignor) on Apr 09, 2013 at 08:20 UTC | |
by LanX (Saint) on Apr 09, 2013 at 08:32 UTC | |
by loituma (Initiate) on Apr 09, 2013 at 08:29 UTC | |
|
Re: How to make a copy of filehandle
by jwkrahn (Abbot) on Apr 09, 2013 at 08:46 UTC | |
|
Re: How to make a copy of filehandle
by Rahul6990 (Beadle) on Apr 09, 2013 at 09:25 UTC |