develooper Front page | perl.perl5.porters | Postings from February 2019

Re: New defined-match operator

Thread Previous | Thread Next
From:
David Nicol
Date:
February 22, 2019 15:48
Subject:
Re: New defined-match operator
Message ID:
CAFwScO87tOBFfNAg9AfUG5oTBAF5EZ6WW36giC+SPt4tue3png@mail.gmail.com
On Fri, Feb 22, 2019 at 9:21 AM Richard Leach <rich@hyphen-dash-hyphen.info>
wrote:

> More seriously, as well as checking for definedness, would there be
> some use for checking for existence? e.g. short circuiting if a nested
> hash structure doesn't have all the specified elements, rather than
> autovivifying some and then warning about uninitialized values.
>

This was essentially the "it" proposal, that got me subscribed to this
mailing list, some moons ago:

A variant of the "exists" test short circuits without vivifying, and has an
associated L-value accessor C<it> that exposes an alias to the target of
the last "exists" call. These would be lexically scoped to allow for

      (exists($some->{complicated}[$container]{access}{goes}{here}) and
something_arbitrary and print it)
         or print "no existo\n";
      it++; # increment
$some->{complicated}[$container]{access}{goes}{here}, autivivving if needed

currently the final level in nested hashes doesn't autoviv when used as a
subroutine argument; perhaps that magic could be extended to not autoviv
intermediates as well.


-- 
"I don't know about that, as it is outside of my area of expertise." --
competent specialized practitioners, all the time

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