in reply to HowTo retrieve the position in a file from the FH

You'd have a lot less trouble if you just used standard filehandles and related functions docuemented in perlfunc, rather than faffing around with those pseudo-object modules that each have their own and slightly different view of things and how things "should work".

open my $fh, '<', $file or die $!; binmode $fh; my $binrec; read $fh, $binrec, 15; my $pos = tell $fh; print "pos = $pos\n"; ## prints 'pos = 15' .... seek $fh, $pos, SEEK_SET; ## go back

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: HowTo retrieve the position in a file from the FH
by Tanktalus (Canon) on Mar 13, 2006 at 17:28 UTC

    Right. And we should get rid of the entire idea of filehandles-as-objects from perl6. Or is that the way we're going? I can't keep up.

    Instead, as reasonablekeith reasonably pointed out, the solution really is to RTFM. Looking at IO::File shows that it derives from IO::Seekable, among others. Since that seemed like a logical next place to look, I went there, found the documentation on getpos, and saw that setpos was right there as well. I tried it out, and it worked wonderfully. I went to post, and noticed that reasonablekeith already had posted exactly that, so I left it alone.

    (Alternate ways of doing things ++. Snide remarks about using a standard module --. Extending the argument ad absurdum, you get the idea to parse XML with built-in regular expressions in perlre because all the XML modules have their own and slightly different view of things and how things should work, when RTFM'ing will still get the job done quickly and reliably.)

      And we should get rid of the entire idea of filehandles-as-objects from perl6.

      Why would you/we/they? Won't they be the 'standard interface'? But that's a ways down the road yet.

      Snide remarks about using a standard module

      Sorry. It wasn't meant, nor do I consider it to be, a snide remark. Simply sage advice for someone starting out with perl whom appears to be rather confused by the profusion of ways of doing things. Start simple and progress.

      Pointing out that IO::File also had methods obj->tell() and $obj->seek(), that actually do what the OP is trying to do, might have been more useful to the OP than obscure references to opaque objects.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.