in reply to uninitialized value $_ in pattern match (m//)

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.
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.

Replies are listed 'Best First'.
Re^2: uninitialized value $_ in pattern match (m//)
by gvinu4u (Acolyte) on Jun 23, 2011 at 07:56 UTC
    Thanks for replies, The basic thing that I'm intending to do is egt Database Connect - SQL, DBMgrTest and Databases from the below line of XML. <suite subfamily="Database Connect - SQL" name="DBMgrTest" family="Databases"> Any way of using a better regular expression to get all the three values into $1,$2 and $3 please let me know.