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

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

Thread Previous | Thread Next
June 10, 2013 10:27
Re: key/value hash and index/valuse array slices syntax
Message ID:
On 3 June 2013 14:06, Ruslan Zakirov <> 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.

How does your patch impact this behavior?

Also what happens if I do:

my $sub_hash= %hash{thing};

does $sub_hash end up with the value 2 if "thing" existed, and with
the value 0 if it didn't?

If someone does this should it warn?

> This feature was discussed [1] back in Feb with Brad Gilbert. We agreed that
> for consistency this should work with arrays too as index/value array slice.
> I've added array functionality. Also, wrote a few basic tests.
> Main question is whether should I continue or stop right there as it never
> will be in the core?
> A quick review of the code [2] would be helpful too.
> [1]
> [2]

Thanks for working on this Ruslan!


perl -Mre=debug -e "/just|another|perl|hacker/"

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