Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Why is it that a hash slice operand to grep,
eg print join "\n", grep /Yeah hoo!/, @x{@bigger_set_of_keys}
adds any missing keys to the hash ? Here's an example,
DB<38> undef %x DB<39> @x{5..10} = ('a' .. 'z')[0..6] DB<40> p join "\n", keys %x 8 10 9 5 6 7 DB<41> p join "\n", grep /a|b/, @x{5..7} a b DB<42> p join "\n", grep /a|b/, @x{1..10} a b DB<43> p join "\n", keys %x 1 10 2 3 4 5 6 7 8 9 DB<44>
Obviously, I am doing something stupid but what might that be ? Splitting the operation like
works fine.@my_values = @x{bigget_set_of_keys} ; @my_filtered_vals = grep /Yeah hoo!/, @my_values ;
What is the best way of cascading slice operations ?
Thank you,
Yours sincerely.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
avoiding autovivification in hash slices
by blakem (Monsignor) on Nov 26, 2001 at 14:53 UTC | |
|
Re: Why is that a hash slice operand to grep adds keys to the hash (if the slice is bigger than the orig set of keys) ?
by rje (Deacon) on Nov 27, 2001 at 01:50 UTC |