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

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

Thread Previous | Thread Next
Ruslan Zakirov
June 11, 2013 12:14
Re: key/value hash and index/valuse array slices syntax
Message ID:
On Tue, Jun 11, 2013 at 2:53 PM, Leon Timmermans <> wrote:

> On Mon, Jun 10, 2013 at 11:41 PM, Ricardo Signes
> <> 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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About