develooper Front page | perl.perl5.porters | Postings from September 2001

error dereferencing array in a tied hash

Thread Next
Steve Sapovits
September 29, 2001 06:10
error dereferencing array in a tied hash
Message ID:

Sorry if this is the wrong list to post this to, but I've looked
everywhere else.  

I have a hash tying package that works EXCEPT when references
are returned and used in block constructs like this:
   my $h = {};
   tie %$h, "MyTie";
   $h->{KEY} = [];
   push(@{$h->{KEY}}, (qw/foo bar/));  # THIS FAILS
The failure is:  Can't use an undefined value as an ARRAY reference.

Replacing the fetch line with one that does an assignment does work:

   push(@{my $x = $h->{KEY}}, (qw/foo bar/));  # THIS WORKS!

If I put a print in FETCH the value is there, as expected, before it
returns in all cases.  

I've built about a half dozen similar hash ties without this problem. 
This tie, like some of the others, is a hash but it doesn't use itself
as the data holder directly -- it refers to another anonymous hash that
implements the hash being tied.

This Tie relies on lots of internal code so I can't post it.  I also
can't reproduce the problem with a smaller tie.  The tie is just using
other hashes behind the scenes for data normalization and validation --
no databases, files, shared memory or anything else unusual.  The hash 
being tied is also a blessed (object) reference.  Everything else works.  
Nothing unusual from the debugger or using -w.  It fails the same across
all versions of Perl 5.5 and 5.6 I tried.  I've looked at the Perl source
and don't see anything there so far.  I'm running on Solaris.  I have not
tried anywhere else yet (next on my list).

Any pointers appreciated.  Sorry if this is OT for this list.

Steve Sapovits

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About