Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^4: Preventing unintended list expansion inside hash literals.

by Athanasius (Archbishop)
on Jan 05, 2017 at 13:00 UTC ( [id://1179018]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Preventing unintended list expansion inside hash literals.
in thread Preventing unintended list expansion inside hash literals.

Hello Ken,

No, you’re right: in the context of the OP’s example code, scalar works fine. I was looking to the more general question:

What's the idiomatic way to guard against unintentionally expanding a non-singleton list into the bodies of your hashes?

A “non-singleton list” can be an empty list (as in the example code), OR a list with more than one element. Use of scalar for the latter case returns the last element of the list, not the first. From the OP’s use of $array_ref->[0] as his example of “a single-element list,” I assumed that in this case he would want the first element of the list. But admittedly this is little more than a guess. :-( Sorry for the confusion.

Cheers,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 23:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found