Here is my input file snippet "Input.xml" (Its a huge XML file of nearly 30MB with 400000 lines):

<Reasons id="ABC" name="PJ1:PJ"> <modDate>2010-03-18T09:20:05.793-03:00</modDate> </Reasons> <Reasons id="DEF" name="PJ2:PJ"> <modDate>2010-03-18T09:19:56.997-03:00</modDate> </Reasons> <Reasons id="GHI" name="ADD"> <modDate>2010-03-18T11:12:00.147-03:00</modDate> </Reasons> <Reasons id="JKL" name="ADD"> <modDate>2010-03-18T11:15:16.597-03:00</modDate> </Reasons>

I am trying to extract all the "Reasons" by reading the file into array and then joining to scalar then retaining only the wanted stuff by substitution. My Perl code is as follows:

#! /bin/env perl use warnings; if (! open R21WORKINGCONFIG, "<", "Input.xml") { die "Cant open Input.xml for input"; } @workingConfig = <R21WORKINGCONFIG>; chomp @workingConfig; $domainProperty = "Reasons"; $scalarWorkingConfig = join "XXXXX", @workingConfig; $scalarWorkingConfig =~ s/.*(XXXXX[ | ]*<$domainProperty .*$domainPr +operty>).*/$1/g; print join ("\n", split (/XXXXX/, $scalarWorkingConfig))."\n"; close R21WORKINGCONFIG;

But unfortunately, the substitute does not match the entire set of "Reasons" but only the last one. Here is the output that I get:

<Reasons id="JKL" name="ADD"> <modDate>2010-03-18T11:15:16.597-03:00</modDate> </Reasons>

The question is why is the substitute command not matching the entire set of Reasons? I think the reg-ex is pretty straight forward. Where is it that I am going wrong?


In reply to How to make substitute greedy like sed's substitute by PerlJedi

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.