On 03/13/2017 02:11 PM, Elizabeth Mattijsen wrote:
On 13 Mar 2017, at 22:06, ToddAndMargo <toddandma...@zoho.com> wrote:
Hi All,
$ perl6 -e 'my $x="ab12cd"; $x ~~ m/ab(1q2)cd/; say "$x\n\$0=<$0>\n";'
Use of Nil in string context in block <unit> at -e line 1
ab12cd
$0=<>
With out the "q" in this, it works. I deliberately put
the "q" to see what would happen when a patter was not
found.
Is there a way around the "use of nil" finger wag
if a patter is not found?
The Nil is not caused by the smart match, but from your attempt to display the
first positional capture (aka $0) of a match that failed.
Or should I always test for its presence first if
there is a possibility the pattern might not exist?
You should test whether the smart match was successful.
my $x="ab12cd"; say "$x\n\$0=<$0>\n” if $x ~~ m/ab(1q2)cd/;
Liz
Hi Liz,
Thank you!
How would you do this if there were several matches in the line?
if $x ~~ m/(ab)(1q2)(cd)/;
Eventually break down an use .defined?
Many thanks,
-T
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~