Hi Chris Daniel,
I need to remove the entities without opening the file.
I'm going to take a guess as to what you mean by this. I assume you have an existing Perl script that uses an XML module to parse the file, and that is what you mean by "opening the file", and you want to make the replacements in the file before running this particular Perl script. The reason the terminology you're using is confusing is that a search & replace on the file will always require opening it.
It is possible but not necessary to use sed for your task, Perl will work just fine, this is a Perl website after all. You can either use a solution like for example what FreeBeerReekingMonk showed here, running that one-liner before you run your script that parses the XML file, or you could even integrate the search and replace into the same script that parses the XML file. Here's a rough idea that takes an input file, runs the search and replace and writes the result to an intermediate file, which you can then open with your XML parser:
my $input_filename = 'foo.xml';
my $temp_filename = 'bar.xml';
open my $ofh, '>', $temp_filename or die $!;
open my $ifh, '<', $input_filename or die $!;
while (<$ifh>) {
s/foo/bar/g;
print $ofh $_;
}
close $ifh;
close $ofh;
# now open $temp_filename with your XML parser
Hope this helps, -- Hauke D |