Perl Monk, Perl Meditation | |
PerlMonks |
Re: Use of uninitialized value $var in pattern match (m//)by Athanasius (Archbishop) |
on Apr 10, 2015 at 12:40 UTC ( [id://1123042]=note: print w/replies, xml ) | Need Help?? |
Hello CropCircle, and welcome to the Monastery! This line:
looks a bit strange to me. If $var contains 'xredy', for example, the match will succeed but $var2 will be set to 1 (“true”):
Is that really what you want? To set $var2 to the string that was matched, you need something like this:
The parentheses within the regex are for capturing, and the parentheses around $var put the match into list context. See perlretut#Extracting-matches. Or you can get the capture in $1:
Hope that helps,
In Section
Seekers of Perl Wisdom
|
|