PerlJedi has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to make substitute greedy like sed's substitute
by Ratazong (Monsignor) on Mar 30, 2010 at 08:55 UTC | |
by PerlJedi (Novice) on Mar 30, 2010 at 09:20 UTC | |
|
Re: How to make substitute greedy like sed's substitute
by Jenda (Abbot) on Mar 30, 2010 at 15:14 UTC | |
|
Re: How to make substitute greedy like sed's substitute
by rovf (Priest) on Mar 30, 2010 at 11:15 UTC | |
|
Re: How to make substitute greedy like sed's substitute
by AnomalousMonk (Archbishop) on Mar 31, 2010 at 00:42 UTC | |
|
Re: How to make substitute greedy like sed's substitute
by kyz (Acolyte) on Mar 31, 2010 at 12:40 UTC | |
|
Re: How to make substitute greedy like sed's substitute
by Anonymous Monk on Mar 31, 2010 at 07:30 UTC |