I'm trying to use seek
to "rewind" to the beginning of a file using the following code:
#! /usr/bin/perl
use strict;
use warnings;
my $infile = $ARGV[0];
open (FH, "<$infile");
while(<FH>) {
chomp;
print $_,"\n";
}
print "one time","\n";
seek FH, 0, 0;
while(<FH>) {
chomp;
print $_,"\n";
}
My input file looks like this:
A A A A A A A
B B B B B B B
I run my program with the following command:
cat file | perl script.pl /dev/stdin
But instead of getting my expected output:
A A A A A A A
B B B B B B B
one time
A A A A A A A
B B B B B B B
I get:
A A A A A A A
B B B B B B B
one time
Why?