in reply to Re: Better way?
in thread Better way?

MeowChow, here's another version using a hash slice instead of a for loop to assign the contents of one hash to another:

my %old = ( 1 => a, 2 => b, 3 => c, 4 => d, 5 => f, ); my @keys = qw(4 5 6 7); #Keys to copy from the old to the new hash my %new; @new{ @keys } = @old{ @keys };

In this case, the difference between using a for loop and a hash slice means a slight edge in speed during benchmarking. However, the larger the data set the wider the gap becomes.