
FishMonger
Veteran
Nov 26, 2008, 8:57 AM
Post #2 of 2
(1390 views)
|
|
Re: [niyas.mohd] reg. exp code to parse xml
[In reply to]
|
Can't Post
|
|
How about a few code comments. First, using simple regexs to parse xml is a bad idea. You really should use an xml parser, such as: XML::Twig http://search.cpan.org/~mirod/XML-Twig-3.32/Twig.pm or one of the many others http://search.cpan.org/search?query=xml&mode=all Your script is missing 2 very important items which should be in every Perl script you write. use warnings; use strict;
Hi, find the sample code --------------------------------------------- #!c:\perl\bin open(INPUTFILE, "+< Soap_Results.xml") or die "Unable to open sample.txt"; If you want to follow the "Best Practices", it would be better to use a lexical var for the filehandle and the 3 arg form of open. Why open the file in read/write mode when you only plan on reading? You're opening "Soap_Results.xml" but the die statement says that you failed to open "sample.txt" and you didn't include the reason it failed.
my $xml_file = 'Soap_Results.xml'; open my $XML, '<', $xml_file or die "Unable to open $xml_file $!"; my (@rawdata, @validdata); while(<INPUTFILE>) { my $Rawdata = $_; Is better written as:
my (@rawdata, @validdata); while ( my $Rawdata = <$XML> ) { if($Rawdata =~ /responseData class|\/(\w){2}\:ClaimID/) { push(@rawdata,"$Rawdata"); #$Rawdata = "$Rawdata"; } } close(INPUTFILE);
push(@rawdata, $Rawdata); You should read perldoc -q quoting There are other items that I could point out, but you get the gist.
|