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

Re: Extend the fat comma to deal with undef

Thread Previous | Thread Next
From:
David Nicol
Date:
October 6, 2016 22:50
Subject:
Re: Extend the fat comma to deal with undef
Message ID:
CAFwScO8aRCKAF7v_VmtP5LmgpUGRKtFA76F5yejmB=Z-pUSCCA@mail.gmail.com
On Wed, Oct 5, 2016 at 11:59 PM, Sam Kington <sam@illuminated.co.uk> 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
moment)

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

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About