I’m trying to use getpos in Perl. I am using a FileHandle object in the code below, and it doesn’t seem to be working. Can anyone tell me what I’m doing wrong?
use strict;
use warnings;
use FileHandle;
my $fh = new FileHandle;
$fh->open("<test.txt") or die "$!";
my $pos = $fh->getpos;
print "pos: \"$pos\"\n";
The output is:
pos: ""
I would expect “0” to be output…
Note the caveat (emphasis added) in the documentation:
Opaque means you shouldn’t pay attention the value: use it only as a parameter in future requests from the module.
Why not use Perl’s
tellandseekoperators?The output of the above program is
0, as you expect.