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

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.

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

    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

      With reguards to your first technical note,
      I didn't specify which two items formed "both". I was refering to perlfunc. :p
      And yes, it's wrong.
      It's not wrong because eval doesn't return undef on error.
      It's wrong because eval doesn't always return undef on error, and there's no mention of that.

      With reguards to your second technical note,
      "eval returns an empty list" meant
      "eval called return with an empty argument list", and
      "An empty list is interpreted as undef in scalar context." meant
      "return interprets an empty argument list as undef in scalar context."
      My statements might have been vague where it didn't matter, but they weren't wrong.

      Update: Expanded a bit