Reputation: 3909
I'm having trouble doing a match for this xml string in perl.
<?xml version="1.0" encoding="UTF-8"?><HttpRemoteException path="/proj/feed/abc" class="java.io.FileNotFoundException" message="/proj/feed/abc: No such file or directory."/>
I want to place a condition on FileNotFoundException
like so:
code snippet:
my @lines = qx(@cmdargs);
foreach my $line (@lines) { print "$line"; }
if (my $line =~ m/(FileNotFoundException)/) {
print "We have an ERROR: $line\n";
}
Error:
Use of uninitialized value in pattern match (m//) at ./tst.pl
Upvotes: 0
Views: 513
Reputation: 91373
You should test $line
inside the foreach loop:
my @lines = qx(@cmdargs);
foreach my $line (@lines) {
print "$line";
if ($line =~ m/(FileNotFoundException)/) {
print "We have an ERROR: $line\n";
}
}
Upvotes: 2
Reputation: 385496
You never assign anything to the variable against which you match (since you create the variable right there inside the if
condition), so it doesn't contain what you say it does.
Use use strict; use warnings;
!!!
It would have given you a warning. Remove the my
.
Upvotes: 5