I have multiple XML files in a folder "c:\srini\perl\in\" ... the structure of all these files are the same ... I need to search for two tags in each XML and if that TAG values has "@@@" in it ...it has to be replaced with "&" ... it has to check for two tag values SHORT_DESC and XXX_NAME ...if any of the TAG value has "@@@" in it ..it has to be replaced with "&".. Below is the XML file ....
<TOPHEADER>
<HEADER>
<NAME>ABC LTD</NAME>
<SHORT_DESC>ABC COMPY @@@ LTD</SHORT_DESC>
<XXX_NAME>ABC COMPANY FOR XXX AND YYY </XXX_NAME>
</HEADER>
<HEADER>
<NAME>XYZ LTD</NAME>
<SHORT_DESC>XYZ COMPY @@@ LTD</SHORT_DESC>
<XXX_NAME>XYZ COMPANY FOR @@@</XXX_NAME>
</HEADER>
<HEADER>
<NAME>DEF LTD</NAME>
<SHORT_DESC>DEF COMPY AND LTD</SHORT_DESC>
<XXX_NAME>DEF COMPANY FOR @@@</XXX_NAME>
</HEADER>
</TOPHEADER>
I'm using the below code to replace the tag value for a single file .. but wanted to know if there is a better way to handle multiple files ....
open (my $input_file, '<', 'c:\srini\perl\in\test1.xml') or die "unable to open $input_file $!\n";
open (my $output_file, '>', 'c:\srini\perl\in\test1_out.xml') or die "unable to open $output_file $!\n";
my $input;
{
local $/; #Set record separator to undefined.
$input = <$input_file>; #This allows the whole input file to be read at once.
}
$input =~ s/@@@/&/g;
print {$output_file} $input;
close $input_file or die $!;
close $output_file or die $!;