Hi,
in my applications often I end up with an hash ref that contains array
refs, and each time I have to insert a new element in the array for a
specific key I write something like:


if ( ! exists $hash_ref->{ $key } ){
    $hash_ref->{ $key } = [];
}

push @{ $hash_ref->{$key} }, $new_value;


Is there a better and shorter pattern to push the new value in an
array ref creating it if it does not yet exists in the hash?

Thanks,
Luca

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to