in reply to Sending output to an xml file
There are three approaches to this problem:
# Instead of >perl -w myscript.pl -some -command -line # you invoke it as >perl -w myscript.pl -some -command -line >output.xml
BEGIN { my $outfile = 'output.xml'; close STDOUT; open STDOUT, ">", $outfile or die "Couldn't create '$outfile': $!"; };
# Instead of sub frobnitz { my ($input) = @_; if ($input =~ /foo/) { $input =~ s!foo!frobnitz!g; print $input; }; }; # write: sub frobnitz { my ($input) = @_; if ($input =~ /foo/) { $input =~ s!foo!frobnitz!g; return "<foo>$input</foo>" } else { return $input; }; }; # ... print frobnitz($in);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sending output to an xml file
by graff (Chancellor) on Sep 29, 2005 at 02:58 UTC |