in reply to Re^2: Blessing interior hashes
in thread Blessing interior hashes

Yup, excellent!

Two little additions:
|| 1 assures a true value when %$ref is an empty hash.
|| 1 avoids the "void context" warning ; 1 would issue.

One little correction:
On error, eval returns false (dualvar 0, ""), not undef.

Replies are listed 'Best First'.
Re^4: Blessing interior hashes
by lodin (Hermit) on Oct 03, 2007 at 19:07 UTC

    On error, eval returns false (dualvar 0, ""), not undef.

    From perlfunc:

    If there is a syntax error or runtime error, or a die statement is executed, an undefined value is returned by eval

    lodin

      I had tested with the following. Note the lack of warning

      >perl -wle"$r=[]; print eval { %$r || 1 }

      Turns out we're both wrong. eval returns an empty list.

      >perl -wle"$r=[]; print scalar(() = eval { %$r || 1 }); 0

      An empty list is interpreted as undef in scalar context.

        Turns out we're both wrong.

        On the first technical note, I'm not wrong because all I did was to quote perlfunc. :-)

        Empty lists are interpreted as undef in scalar context.

        On the second technical note, there's no such thing as empty lists in scalar context, as far as I know. Your examples only show that eval returns the empty list in list context.

        eval returns an empty list.

        In list context it returns an empty list. In scalar context it returns undef. It doesn't return an empty list that evaluates to undef, because if it's in scalar context there can't be any list.

        IMHO, if context isn't specified in the documentation, all contexts are implied. So either perlfunc needs to be fixed to say that it returns undef in scalar context and the empty list in list context, or eval need to return undef in list context too.

        lodin