Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer


by sgifford (Prior)
on Apr 02, 2006 at 07:36 UTC ( #540711=perlquestion: print w/replies, xml ) Need Help??

sgifford has asked for the wisdom of the Perl Monks concerning the following question:

I'm having some trouble with tying a filehandle on Perl 5.6.1 (Debian Woody). The minimal testcase I've got is like this:
#!/usr/bin/perl + use warnings; use strict; use Symbol; use IO::Handle; + our $f1; $f1 = gensym; open($f1,"<&STDIN") or die "dup of STDIN failed\n"; tie *$f1, 'TieTest'; print "Read: ",scalar(<$f1>); + package TieTest; sub TIEHANDLE { my $class = shift; my $obj = { }; bless $obj, $class; warn "TIEHANDLE: $obj\n"; $obj; } + sub READLINE { warn "READLINE\n"; return "line\n"; }
When I run it, I get:
TIEHANDLE: TieTest=HASH(0x80fcacc) Use of uninitialized value in <HANDLE> at line 14. readline() on unopened filehandle at line 14. Use of uninitialized value in print at line 14. Read:

It seemed to work for some other monks in the chatterbox, so it might be a version-specific problem.

Anybody have any ideas for making this work? All I'm really looking for is a way to make my filehandle objects work with regular perl file operations, like seek and angle-brackets.

The actual code emulates seek on a remote file via FTP, using the FTP REST and ABOR commands. If I open a ZIP file and pass it to Archive::Zip, it's able to read the table-of-contents of a multi-GB ZIP file and extract individual files without downloading the whole thing. I'm trying to get everything polished up for CPAN, and this is about the last thing on my list.


Update: Two more data points: First, everything besides READLINE works: read, getc, seek, tell, eof, etc. Second, everything works just fine on a perl 5.8.3 system I had handy.

Replies are listed 'Best First'.
Re: TIEHANDLE problem
by bart (Canon) on Apr 02, 2006 at 10:31 UTC
    I'm one of the monks who went over this with sgifford in the Chatterbox (davido is the other), I'm completing sgiffords question with some of the findings in the chatterbox. We've established the following:
    1. Code works as is, in perl 5.8.7
    2. Code works with perl 5.6.1 provided you replace the $f1 with an actual globale handle, like F1:
      tie *F1, 'TieTest'; print "Read: ",scalar(<F1>);
    3. Replacing the gensym with an instance of IO::Handle doesn't make a difference (that's why the line use IO::Handle is in this code).
    4. Opening $f1 first to a different handle in order to make the handle exist in the glob, doesn't help.

    We're all very curious to what is going on, and if there's a way around it apart from upgrading Perl. I personally suspect that there's a problem with autovivification of the filehandle with the tie, but it's just a suspicion.

    Any insight from somebody who really knows what is going on, and preferably, a way to make it work on perl 5.6.1, would be appreciated.

    Update I've now had a chance to test it on Indigoperl (Activeperl compatible) 5.6.1 on Win32: I can confirm it has the same problem there. It looks like an actual bug in 5.6.x to me.

      It probably is a 5.6.x bug, but what is conspicuously abscent is any "easy to find" mention of its being fixed in any of the perldelta POD's. least given a quick eyeball skimming of each delta POD from early 5.6.x through present, followed by grepping for a variety of search terms. Can anyone uncover any documentation on the subject?


Re: TIEHANDLE problem
by idsfa (Vicar) on Apr 02, 2006 at 08:04 UTC

    Results on my etch system:

    TIEHANDLE: TieTest=HASH(0x818e0d0) READLINE Read: line

    Results on sid:

    TIEHANDLE: TieTest=HASH(0x818c998) READLINE Read: line

    woody is obsolete. You should update to a supported version if you want anything to work.

    The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon
      It's still supported by security releases until etch is released, and everything else on the system works perfectly, so that seems like an overly strong statement...
Re: TIEHANDLE problem
by nothingmuch (Priest) on Apr 02, 2006 at 08:54 UTC
    Please take over Tie::FTP if you'd like to improve it. It sounds like you could actually make it useful =)

    zz zZ Z Z #!perl

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://540711]
Approved by davido
Front-paged by davido
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2023-02-08 10:45 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (41 votes). Check out past polls.