I tried the below code snippet and the seek function doesn't seem to work.
funct("ls -ltr /scratch/dummy/dum*");
sub funct {
print "\nRecording\n";
open(SENSOR_LIST1, "$_[0] |") || die "Failed to read sensor list: $!\n";
for $sensor_line1 (<SENSOR_LIST1>) {
print "$sensor_line1";
}
my $pos = tell SENSOR_LIST1;
print "\nposition is $pos"; #Here the position is 613
print "\nRecording again";
seek (SENSOR_LIST1, SEEK_SET, 0);
$pos = tell SENSOR_LIST1; # Here again the position is 613, even after a seek
print "\nposition now is $pos";
for $sensor_line1 (<SENSOR_LIST1>) {
print "$sensor_line1";
}
close SENSOR_LIST1;
}
Note: All variants of seek doesn't work.
Output:
The position does not change even after the seek. It remains in 613.
Can you guys, check and let me know what is the issue here?
Thanks.