Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Using a hash with the @ sigil

by 1nickt (Canon)
on Jul 26, 2015 at 19:04 UTC ( [id://1136365] : note . print w/replies, xml ) Need Help??


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.

The way forward always starts with a minimal test.