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 19:29
Subject:
Re: New defined-match operator
Message ID:
CAFwScO9gR0P6CVjFLMkDavXEp05wTgtPLjKRLCzJCEzz5=HWLw@mail.gmail.com
defined and /($regex)/ for $string;   # this works, sort of

$ perl -le 'my $string; $d=defined and /(a)/ for $string; $d or print "not
defined"'
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
$cap'
a

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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About