in reply to Defining an anonymous hash with slices and lists.

How is Perl to know that:

@{ qw/ one two three / } = (1..3)

is intended to be a hash declaration, not a list assignment?

Replies are listed 'Best First'.
Re: Re: Defining an anonymous hash with slices and lists.
by davido (Cardinal) on Aug 27, 2003 at 21:50 UTC
    Well, actually the following does create a hash:

    my %hash; @hash{ qw/ one two three / } = ( 1..3 );

    And if you don't care about strictures, the  my %hash; part can even be eliminated.

    The problem comes when trying to pluck one of its values while defining it, like this:

    $someval = ${@hash{ qw/ one two three / } = ( 1..3 )}{two};

    And it only gets worse if you try to make it anonymous by removing the name "hash".

    Dave

    "If I had my life to do over again, I'd be a plumber." -- Albert Einstein