#!/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 inat 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!
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.
tie *F1, 'TieTest'; print "Read: ",scalar();
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.
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. ...at 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?
Dave
perlmonks.org content © perlmonks.org and bart, davido, idsfa, nothingmuch, sgifford
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03