- %h = undef results in %h having one key, '', mapped to undef (and also gives an 'odd number of hash elements' warning)
- @a = undef results in @a having one element, undef
- undef %h
- %h = ()
So just as you might have this:
@a = (1,2,3); print @a[1,2];and get '23', then you might have this:
%a = qw(alpha 1 beta 2 gaga 3);
print @a{ qw(beta gaga) };
and also get '23'.
NB that it is an @ and not a % as the first character there.
To slice a hash reference just replace @a above with @$r or @{$r} .
(New) You can also slice in a sort of 'select column' way, where your result is a subset of the hash's keys and values rather than just values:
%a = qw(alpha 1 beta 2 gaga 3);
%b = %a{ qw(beta gaga) };
and end up with %b being (beta => 2, gaga => 3);
To do that with a reference, replace %a above with %$r or %{$r} .
This works in Perl 5.24 but not in 5.8.2 .
built in such a logical wayI always imagined the 'Masterpiece' to be some kind of wonderful watch or clock that kept time far faster than necessary, and whenever I found a bug in my code, I'd think 'Yeah, I built it in such a logical way / It ran a hundred years to a day.'
It ran a hundred years to the day.
So I'm a bit disappointed, having finally followed up the reference, to find that it's a just some rustic humour by Oliver Wendell Holmes about a 'wonderful one-hoss shay' - that's a chaise to us, one of those bouncy little horse-drawn carriages.