TIEHANDLE problem
sgifford
created: 2006-04-02 03:36:45
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  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!

Re: TIEHANDLE problem
created: 2006-04-02 04:04:03

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
Re^2: TIEHANDLE problem
created: 2006-04-02 09:02:51
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
created: 2006-04-02 04:54:07
Please take over Tie::FTP if you'd like to improve it. It sounds like you could actually make it useful =)

-nuffin
zz zZ Z Z #!perl
Re: TIEHANDLE problem
created: 2006-04-02 06:31:17
I'm one of the monks who went over this with [sgifford] in the Chatterbox ([davido] is the other), I'm completing [sgifford]s 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();
    
  3. Replacing the gensym with an instance of [cpan://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.

Re^2: TIEHANDLE problem
created: 2006-04-04 02:55:38

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