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


In reply to Assigning REGEX Match to a separate variable? by mmartin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.