sub FETCH { my ($this, $key)=@_; return $this->{'l'}{$key} if exists $this->{'l'}{$key}; print "trying f's $key: $this->{f}{$key}\n"; $this->{'l'}{$key}=eval($this->{f}{$key}); return $this->{'l'}{$key}; } Can't use an undefined value as a HASH reference at t2.pl line 27.<BR> +<BR> Why does pwotie's FETCH work ok with $o{0} called first, but fail when + $o{0}->{hi} is called first?

It doesn't work, because $o{0} is undefined, and you're trying to use that as a hash reference. Remember that when you use a tied hash, you can't count on complex vivification. You'll have to initialise a hash ref yourself:

sub FETCH { my ($this, $key) = @_; return $this->{l}{$key} if exists $this->{l}{$key}; # I don't know what you're doing, but eval is scary :) # Consider using a sub ref (sub { ... } or \&subname) instead $this->{l}{$key} = eval $this{f}{$key}; # Create a new hash ref if the eval returned undef $this->{l}{$key} = { } if not defined $this->{l}{$key}; return $this->{l}{$key}; }

U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk


In reply to Re: TIEHASH hiccup? by Juerd
in thread TIEHASH hiccup? by jhanna

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.