in reply to Scalar ref acting as simulatenous hash and array?

Maybe I've completely missed the point here, but couldn't you use 'wantarray', and if it returns true, return a list, otherwise return a hash? Or is that too easy?
  • Comment on Re: Scalar ref acting as simulatenous hash and array?

Replies are listed 'Best First'.
Re: Re: Scalar ref acting as simulatenous hash and array?
by davorg (Chancellor) on Oct 19, 2001 at 19:46 UTC

    Both array assignment and hash assignment cause the RHS to be evaluated in list context. wantarray can't tell the difference between array and hash assignment.

    my @arr = get_it(); my %hash = get_it(); sub get_it { if (defined wantarray) { print wantarray ? 'list' : 'scalar'; } else { print 'void'; } print " context\n"; return; }

    This prints "list context" twice.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you don't talk about Perl club."

Re: Re: Scalar ref acting as simulatenous hash and array?
by dragonchild (Archbishop) on Oct 19, 2001 at 19:46 UTC
    At the base of it, hashes are lists. wantarray determines between scalars and hashes-or-lists.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.