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, |
|
|---|