G'day gregory-nisbet,
"What's the idiomatic way to guard against unintentionally expanding a non-singleton list into the bodies of your hashes?"
I don't know if there's an idiom for that specific case; however, as a general case, you can use scalar to force scalar context. So, if you're happy to have undef values in your hash:
key1 => scalar(some_key($bar))
If you don't want undef values and are using perl v5.10, or higher, you can do something like these:
key1 => (some_key($bar) // 0) key1 => (some_key($bar) // [])
If none of those suit, then what you're currently doing ("use an intermediate scalar variable") seems like a perfectly fine solution.
— Ken
In reply to Re: Preventing unintended list expansion inside hash literals.
by kcott
in thread Preventing unintended list expansion inside hash literals.
by gregory-nisbet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |