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 11, 2013 12:14
Subject:
Re: key/value hash and index/valuse array slices syntax
Message ID:
CAMOxC8um1pPBMmVoJpuncMPNj0uVWPTnDz0nGn0GUh7Ujc=_=g@mail.gmail.com
On Tue, Jun 11, 2013 at 2:53 PM, Leon Timmermans <fawaka@gmail.com> wrote:

> On Mon, Jun 10, 2013 at 11:41 PM, Ricardo Signes
> <perl.p5p@rjbs.manxome.org> wrote:
> > I am interested in the answers to Yves' questions, and I think that these
> > slices look worth pursuing further.  I think there are going to be a lot
> of
> > questions about how they should work at the edges to figure out, but
> given the
> > broad strokes, this is a feature that I would totally use and that seems
> quite
> > sensible.
>
> I find myself missing this feature with some regularity, I would
> really like to have this.
>
> One question I do have: what should it do with nonexistent keys? E.g.
>
> my %first = (a => 1, b => 2);
> my %second = %first{qw/a c/};
>
> Should %second now contain «c => undef», not no c at all? I think I'm
> currently leaning towards the latter, it seems like the more useful
> behavior to me.
>

It's open for discussion. May be it is more useful, but I see both cases in
my code. At this moment code result in «c => undef» and it's consistent
with other slice ops. If only we had op modifiers for such ops like we have
for s/// and m///.

Interesting thought is to make the following work like you want:

my %second = exists %first{qw/a c/};


> Leon


-- 
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