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

Re: New defined-match operator

Thread Previous | Thread Next
David Nicol
February 22, 2019 19:29
Re: New defined-match operator
Message ID:
defined and /($regex)/ for $string;   # this works, sort of

$ perl -le 'my $string; $d=defined and /(a)/ for $string; $d or print "not
not defined

the captures seem lost in the implied scope?
$ perl -le 'my $string="abc"; defined and /(a)/ for $string; print $1'

they are available as match results though
$ perl -le 'my $string="abc"; defined and ($cap)=/(a)/ for $string; print

This might be construed as a bug:
$ perl -le 'my $string="abc"; defined and my ($cap)=/(a)/ for $string;
print $cap'

$ perl -le 'use strict;my $string="abc"; defined and my ($cap)=/(a)/ for
$string; print $cap'

my command line perl is only 5.10;  I don't know if a more recent strict
will catch that a lexical declared to the left or a postfix for isn't
available outside of there, or if it now is.

"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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About