Why does FileHandle :: getpos on an open descriptor return an empty string instead of 0?

I am trying to use getposin Perl. I am using an object FileHandlein the code below and does not seem to work. Can someone tell me what I am 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";

Conclusion:

pos: ""

I expect "0" to be printed ...

+3
source share
2 answers

Note the disclaimer (highlighted added) in the documentation :

C fgetpos fsetpos, FileHandle::getpos , FileHandle, FileHandle::setpos .

Opaque , : .

Perl tell seek?

#! /usr/bin/perl

use warnings;
use strict;

open my $fh, "<", $0 or die "$0: open: $!";
print tell($fh), "\n";

0, .

+4

FileHandle , , getpos, , , . , , setpos. , (fgetpos fsetpos), C fpos_t. seek tell, , , .

+4

Source: https://habr.com/ru/post/1751825/


All Articles