develooper Front page | perl.perl5.porters | Postings from October 2016

Re: Extend the fat comma to deal with undef

Thread Previous | Thread Next
David Nicol
October 6, 2016 22:50
Re: Extend the fat comma to deal with undef
Message ID:
On Wed, Oct 5, 2016 at 11:59 PM, Sam Kington <> wrote:

> There are two related things that annoy me about writing Perl at the
> moment. The first is the way hashes are just lists packed into pairs, so if
> you say
>     mandatory(
>         thing => $thing,
>         this => this_does_something(),
>         that => that_does_something(),
>     );
> and this_does_something() returns an empty list, you end with it
> collapsing to e.g. mandatory(thing => $thing, this => ‘that’,
> $whatever_that_returned) and Perl complains about an odd-numbered list.

Without testing or consulting documentation, I understand that one of the
things fat-comma does is put its left side in SCALAR context. That can be
used to make your example do what you want, by using fat commas between the
pairs instead of just between the keys and values. Without violating the
expectation that fat comma is only
used after keys, wrapping the function calls in scalar(do_something())
should coerce
empty list to undef also.

I didn't fully understand the second gripe but I think it might evaporate
based on the above answer.

David Nicol (seeking part time telecommuting perl hacking work at the

"Teaching radical novelties is our main safeguard against dictatorships"
-- Edsger W. Dijkstra

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About