use strict;
seek DATA, 0, 0;
print while <DATA>;
__DATA__
This
is
a
test
From playing with that, you'll see that the seek returns to the beginning of the file, not the beginning of DATA. To correct that, you'll want to tell where DATA starts:
use strict;
my $start = tell DATA;
seek DATA, $start, 0;
print while <DATA>;
__DATA__
This
is
a
test
Update: Reading jmcnamara's response. Boy, do I feel stupid. However, I'm now tempted to launch into my don't name a filehandle DATA rant, since this is a source of confusion (as demonstrated above). I recall ranting about this before. Humph. Maybe I'm just embarrassed :)
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats. |