in reply to Using a hash with the @ sigil
Replying to myself for the archives ...
Not more than a couple of days after posting this and learning from the replies, I had cause to use a hash slice in my work. In a sub that can be called with a single argument consisting of a single value or a list, I was returning a hashref of objects in all cases.
Much better to return the object directly if the sub is called with a single value:
return (scalar keys %data == 1) ? @data{ keys %data } : \%data;
Very cool. Thanks again, monks.
|
|---|