in reply to Declaring and initializing a hash with a list of keys and a list of values

That depends on fairly subtle scoping semantics. Are you positive that no future Perl will ever localize that hash to the loop? I would be concerned...
  • Comment on Re (tilly) 1: Declaring and initializing a hash with a list of keys and a list of values

Replies are listed 'Best First'.
Re: Re (tilly) 1: Declaring and initializing a hash with a list of keys and a list of values
by danger (Priest) on May 15, 2001 at 22:26 UTC

    And these 'subtle scoping issues' render the output of Deparse incorrect:

    $ perl -MO=Deparse -e '@$_{1,2,3}=(4,5,6) for \my %hash;print keys %ha +sh' foreach $_ (\my(%hash)) { @$_{1, 2, 3} = (4, 5, 6); } print keys %hash; -e syntax OK

    Thus, people who try to understand it via the Deparsed version may be somewhat disappointed.

Re: Re (tilly) 1: Declaring and initializing a hash with a list of keys and a list of values
by merlyn (Sage) on May 15, 2001 at 21:55 UTC
Re: Re (tilly) 1: Declaring and initializing a hash with a list of keys and a list of values
by Anonymous Monk on May 15, 2001 at 22:08 UTC
    So what? He doesn't access it in the loop. Does it matter if it's localized?
      The purpose of the loop is to initialize a hash that he wants to be available afterwards. If the scoping changes then he has initialized a private hash that disappears before he ever gets a chance to use it. Oops...

      strict would catch this change.

        But then there must be a block for my. But the expression behind for could be arbitrarily complicated and must be evaluated in a wider context. Then there is an equivalency to map to maintain.
        map {@$_{@keys}=@values}\my%hash;
        and when were functionarguments a block?