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!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|