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 tietest.pl line 14. readline() on unopened filehandle at tietest.pl line 14. Use of uninitialized value in print at tietest.pl 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.

Thanks!

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.


In reply to TIEHANDLE problem by sgifford

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.