Jim Gibson wrote:
On Oct 25, 2013, at 4:46 PM, Shaji Kalidasan wrote:
Dear Perlers,
I am trying to print the matching lines using __DATA__ filehandle and
for the very first time it prints the desired lines, but as soon as I
rewind it using seek, it is printing lines from the very beginning
which is not the desired result (as it prints from the start). I want
to rewind only the __DATA__ part.
As you have discovered, the special file handle DATA is opened to the
source file for your program. When the compiler encounters either of
the following lines in your source file:
__END__
__DATA__
it stops reading the source file and leaves the file handle open at
that point. The first time you read the<DATA> file handle, you get
the line after the '__DATA__' line. But when you rewind the file
handle, it is positioned at the beginning of the file, and you get to
read your program.
You have two choices (at least):
1. Save the position of the file handle when you enter the program:
my $data_pos = tell(<DATA>);
<DATA> is the same as readline( DATA ) which will not work with tell().
It should be just:
my $data_pos = tell DATA;
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/