Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare XML string to records in a text file?

Status
Not open for further replies.

kre1973

IS-IT--Management
May 5, 2006
47
US
I have the following script below in where I read in certain elements in a XML file and write them to a text file. What I need to do is before I write to the file is to compare the records in the text file to the XML elements read in. If any of the records in the file matches the XML elements, then don't write it out to the text file...

Copy of the text file:

Thursday, November 01, 2007|5:07am|8:45am|4:55am
Friday, November 02, 2007|1:50am|3:25am|1:50am
Monday, November 05, 2007|4:29am|5:47am|4:38am
Tuesday, November 06, 2007|6:41am|8:05am|6:44am
Wednesday, November 07, 2007|4:13am|5:42am|4:22am
Thursday, November 08, 2007|4:08am|5:36am|4:53am
Friday, November 09, 2007|2:09am|3:29am|Not yet complete
Monday, November 12, 2007|6:51am|run|7:16am
Tuesday, November 13, 2007|4:18am|5:28am|4:54am
Wednesday, November 14, 2007|4:27am|5:57am|4:16am
Thursday, November 15, 2007|6:34am|Running;|6:35am

Code:
#!/opt/perl/bin/perl
 
use XML::Simple;
my $InputFile = "/Automation/MSR_XML_HTML/Previous.xml";
my $OutputFile = "/data/EBIS_Output.txt";
 
open (IN, "$InputFile") or die "$InputFile $!";
open (OUT, ">>$OutputFile") or die "$OutputFile $!";
 
my $ref = XMLin($InputFile);   
 
print OUT (@{$ref->{Info}}{qw(TODAY)}),'|', join('|',map/(\S+)/,@{$ref->{Info}}{qw(TNC RPI CMHM)}),"\n";     
 
close IN;
close OUT;



thanks
 
You didn't make much effort to solve your problem.
Read first the OutputFile into a hash where a key is a line and all have a value of 1, then before doing [tt]print OUT[/tt] check whether the line you would print exists in the hash.
In the FAQs you'll find some examples on how to do similar things with files and hashes.

Franco
: Online tools for structural design
: Magnetic brakes for fun rides
: Air bearing pads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top