develooper Front page | perl.perl5.porters | Postings from July 2013

Re: postfix dereference syntax

Thread Previous | Thread Next
From:
Eric Brine
Date:
July 4, 2013 13:40
Subject:
Re: postfix dereference syntax
Message ID:
CALJW-qF1wqj7CMUcyhWyPRPC+CGsBcp+ED4UGufQW5PaMU9Xww@mail.gmail.com
On Wed, Jul 3, 2013 at 11:02 AM, David Golden <xdg@xdg.me> wrote:

> On Wed, Jul 3, 2013 at 10:23 AM, Dave Mitchell <davem@iabyn.com> wrote:
> >     expr->[]
> >     $a->[1,5,7]
>
> This is even more attractive to me when considered together with
> normal element access:
>
>     $array->[]; # dereference
>     $array->[$i]; # single element
>     $array->[@list]; # array slice
>
>     $hash->{}; # dereference
>     $hash->{$n}; # single element
>     $hash->{@list}; # hash slice
>

What's the output of

sub f { say wantarray || 0 }
$array->[ f() ]
$hash->{ f() }

Right now, it's 0 0, so  the following aren't backwards compatible:

$array->[@list]
$hash->{@list}

It bugs me slightly that [] and {} look "empty" when in fact they
>
return everything


Is ->[*] available?

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