# test_hash comparable code for hash slicesce # use v5.20; my %h = ( blonk => 2, foo => 3, squink => 5, bar => 8); my %subset; %subset = %h{ 'foo', 'bar' };; dump_subset("New version"); $subset{bell} = 7; # Take that, Unicode! dump_subset("Updated"); #------------------- Equivalent pre-5.20 code # %subset = (); # Reset for my $x ('foo', 'bar') { $subset{$x} = $h{$x}; } $subset{baz} = 42; dump_subset("Original with added"); sub dump_subset { say "\n", shift, "\n"; while (my ($k, $v) = each %subset) { say "Key = $k value = $v"; } } # test_hash End