in reply to uninitialized value $_ in pattern match (m//)
Whenever you do a match, you need to check whether it succeeded or not. You never checked whether the first $subfamily match was true--like you did with the second match.use strict; use warnings; use 5.010; my $line = 'hello world'; my ($subfamily) = $line =~ /goodbye/; #no match, and list context on the left, so m// returns () say "-->$subfamily<--"; if ($subfamily =~ /x/) { say 'yes'; } --output:-- Use of uninitialized value $subfamily in concatenation (.) or string a +t perl.pl line 10. --><-- Use of uninitialized value $subfamily in pattern match (m//) at perl.p +l line 11.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: uninitialized value $_ in pattern match (m//)
by gvinu4u (Acolyte) on Jun 23, 2011 at 07:56 UTC |