in reply to Seaching for text in string and comparing to xml, if not found print text
This could solve your purpose.
my $file = 'Events.txt'; open $info, "<", $file or die "Couldn't open events file: $!"; open $xml, "<", 'XML_FILE.xml' or die "Couldn't open xml file: $!"; open $output, ">", 'OUTPUT.txt' or die "Coudn't open output file: $!"; my $found = 0; #Flag for indication while(my $line = <$info>) { @get_data = split ',' ,$line; $alert_ID = $get_data[5]; seek $xml, 0, 0; # Seek to the beginning, to scan from beginning f +or each ID. while(my $xml_line = <$xml>) { if ($xml_line =~ m|<ALERT_ID>$alert_ID</ALERT_ID>|) { $found = 1; last; } } if ( $found == 1 ) { print "$alert_ID Found.\n"; $found = 0; } else { print $output "@get_data"; } } close $info; close $xml; close $output;
If you don't want anything else to be considered from the XML file. You can remove the other lines(either using sed or grep) before executing the script. It would reduce the processing time significantly.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Seaching for text in string and comparing to xml, if not found print text
by tobyink (Canon) on Feb 14, 2013 at 08:18 UTC |
In Section
Seekers of Perl Wisdom