in reply to Adding to a hash?

I understand what you're trying to do, but you just can't... not like that. Sometimes however, it's helpful to use a hash slice:

my %hash = ( this => 1, that => 2 ); @hash{ qw/ those these / } = ( 3, 4 );

The list of keys can be anything that resolves to a list, including an array or a subroutine call so long as it's properly disambiguated so as not to look like a bareword key.

If the object is to add a whole bunch of new elements at once, that's where slices can be quite helpful.


Dave

Replies are listed 'Best First'.
Re^2: Adding to a hash?
by bradcathey (Prior) on May 19, 2005 at 00:43 UTC

    This is also supports my methods which do require adding lots of pairs at different times. Great solution. Thanks.


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot