in reply to Considering hash slices, past, present and future

If you want a syntax where things line up, just write a function:
# Takes a hash reference and a list of key/value pairs. # Assigns those keys to those values in the hash sub add_to_hash { my $h_ref = shift; while (@_) { my $key = shift; my $value = shift; $h_ref{$key} = $value; } }
Now it is easy to get the syntax you want:
add_to_hash(\%my_hash, key1 => "value1", key2 => "value2", # ... );

UPDATE
Fixed typo pointed out by grinder.

Replies are listed 'Best First'.
(bbfu) (syntax suga) Re2: (tilly) 1: Considering hash slices, past, present and future
by bbfu (Curate) on Oct 26, 2001 at 07:14 UTC

    Coincidentally, I was thinking just last week about writing a Tie::StdHash module that overloaded addition for just such an effect...

    I was curious, do you think that would be overkill for what amounts to just some syntatic sugar? Would it be better to just go with a simple function call, or is there perhaps some worth to be found in creating a whole module/class devoted to adding (and perhaps subtracting) hashes?

    bbfu
    Seasons don't fear The Reaper.
    Nor do the wind, the sun, and the rain.
    We can be like they are.