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:25
Subject:
Re: key/value hash and index/valuse array slices syntax
Message ID:
CAMOxC8t0x2yV1k32iodVFVZJ5w03CxrHJF-49Kh6pSwy6LCUFw@mail.gmail.com
On Tue, Jun 11, 2013 at 3:06 PM, Mark Overmeer <mark@overmeer.net> wrote:

> * Leon Timmermans (fawaka@gmail.com) [130611 10:53]:
> > 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.
>
> Do we need this compact syntax, or can we get
>
>   my %second = slice %first, qw/a c/;
>

This is very doable as module and would be fast if written in XS.

I'm pushing my idea as it fits within existing syntax for slices and I
think completes the picture.


Love to have it in code, maybe in List::Util.
> (there already is a Hash::Slice)
>
> And I still love to have a
>
>   push %grow, @pairs;     # or
>
  merge $grow, @pairs;
>

I love push to work on hashes, but it's semi-offtopic.

You're right that new functionality can be implemented as a keyword or
keyword like function and interface can be very similar to `push`, but if
you have $h{'a'}, @h{qw/a b/} then it's natural to have %h{qw/a b/}.


> --
> Regards,
>
>                MarkOv
>
> ------------------------------------------------------------------------
>        Mark Overmeer MSc                                MARKOV Solutions
>        Mark@Overmeer.net                          solutions@overmeer.net
> http://Mark.Overmeer.net                   http://solutions.overmeer.net
>
>


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