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:
Aristotle Pagaltzis
Date:
June 11, 2013 20:22
Subject:
Re: key/value hash and index/valuse array slices syntax
Message ID:
20130611202236.GA13738@fernweh.plasmasturm.org
* Eric Brine <ikegami@adaelis.com> [2013-06-11 20:50]:
> On Tue, Jun 11, 2013 at 1:21 PM, Aristotle Pagaltzis <pagaltzis@gmx.de>wrote:
> > More importantly, given hash slices that *omit* non-existent keys,
> > it is much harder to get the opposite behaviour. I cannot even think
> > of any sensible way to do it as an expression within the same
> > statement, only if I accept multiple statements, by doing such as
> >
> >     my %second = %first{qw/a c/};
> >     @first{qw/a c/} = @first{qw/a c/};
> >
>
> Still two statements, but this is simpler:
>
> my %second;
> @second{qw/a c/} = @first{qw/a c/};

I purposefully tried to use hash slice syntax for this to show how hard
it is to achieve the opposite of its default behaviour if that omitting
non-existents is its default.

But you have a point – if omitting the hash slice altogether is more
concise in that case, that is another illustration right there that one
default is more flexible than the other.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

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