Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Preventing unintended list expansion inside hash literals.

by vr (Curate)
on Jan 05, 2017 at 09:47 UTC ( [id://1179003]=note: print w/replies, xml ) Need Help??


in reply to Preventing unintended list expansion inside hash literals.

%$hash_ref or return; line is redundant, it doesn't guard from not a hashref being passed to sub, and each returns undef in scalar context on empty hash, anyway.

If sub is guaranteed a hashref as an argument, then iterator could be reset BEFORE using each, and, not sure if "idiomatic", but definitely shorter sub can be

sub some_key { keys %{$_[0]} ? scalar each %{$_[0]} : undef }

p.s. Shorter:

sub some_key { keys %{$_[0]}; scalar each %{$_[0]} }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1179003]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-03-28 10:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found