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

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

Thread Previous | Thread Next
Aristotle Pagaltzis
June 11, 2013 20:22
Re: key/value hash and index/valuse array slices syntax
Message ID:
* Eric Brine <> [2013-06-11 20:50]:
> On Tue, Jun 11, 2013 at 1:21 PM, Aristotle Pagaltzis <>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.

Aristotle Pagaltzis // <>

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