http://www.perlmonks.org?node_id=963057

mmartin has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I have what is probably a simple question for you all.
How can I set a separate variable to the output of a REGEX match...?

The line I'm looking at is part of an XML file, and looks something like this(below):
<String name="changeTypeName">Modified</String>"

I've tried the following but I'm getting an integer as the new variable's data instead of the string:
FYI: the array "@reportData" holds all the file's lines...
### The final result of this should be the string "Modified" from the +example line given above... for (my $x = 0; $x <= $#reportData; $x++) { if ($reportData[$x] =~ /^(\s+)(\<String name="changeTypeName"\>)/) { (my $changeType) = $reportData[$x] =~ /\>[A-z]+\</; # my $changeType = $reportData[$x] =~ /\>[A-z]+\</; # $reportData[$x] =~ /\>[A-z]+\</; # my $changeType = $reportData[$x]; # my $changeType = $1 if $reportData[$x] =~ /\>[A-z]+\</; print "Change Type is = $changeType\n"; } }
While looping through the array it finds the correct line, so the "if statement" is working correctly. But I can't seem to get the value of the REGEX match within the "if statement" to be assigned to the variable $changeType...?

If anyone has any suggestion, please let me know.


Thanks in Advance,
Matt