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

Re: key/value hash and index/valuse array slices syntax

Thread Previous | Thread Next
From:
Ruslan Zakirov
Date:
June 16, 2013 10:10
Subject:
Re: key/value hash and index/valuse array slices syntax
Message ID:
CAMOxC8tuyARGUY8gYPBagtM_TAz_83PNeFYZXCUswAjnKM4DTQ@mail.gmail.com
On Mon, Jun 10, 2013 at 2:27 PM, demerphq <demerphq@gmail.com> wrote:

> On 3 June 2013 14:06, Ruslan Zakirov <ruz@bestpractical.com> wrote:
> > HI,
> >
> > I've updated patches that add key/value hash slices to perl syntax:
> >
> > my %sub_hash = %hash{qw(some keys go here)};
>
> Sounds cool.
>
> However note that it is legal, but deprecated to write this:
>
> $ perl -le'my $hash={foo=>"bar"}; print %$hash->{foo};'
> Using a hash as a reference is deprecated at -e line 1.
> bar
>
> How does your patch impact this behavior?
>

./perl -Ilib/ -w -E 'my $h = { 1..10 }; say %$h->{3,5};'
Using a hash as a reference is deprecated at -e line 1.
Use of uninitialized value in say at -e line 1.

Corresponding op tree:

k     <@> say vK ->l
a        <0> pushmark s ->b
j        <2> helem sK/2 ->k
d           <1> rv2hv[t5] sKR/1 ->e
c              <1> rv2hv[t4] sKR/1 ->d
b                 <0> padsv[$h:47,48] sM/DREFHV ->c
i           <@> join[t6] sK/2 ->j
e              <0> pushmark s ->f
-              <1> ex-rv2sv sK/1 ->g
f                 <$> gvsv(*;) s ->g
g              <$> const(IV 3) s ->h
h              <$> const(IV 5) s ->i

Above is eqal to perl 5.16. I think it's correct to leave it this way.

-- 
Best regards, Ruslan.

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