From: "Scott, Joshua" <[EMAIL PROTECTED]>
> Let me add a little more info regarding my question. The subroutines
> are already setup and can't be modified easily. The basic task of all
> the different subs is to print to STDOUT. I'd really like to be able
> to call this sub from another script and somehow redirect the output
> to a file without modifying the subs code.
Most probably they do NOT write to STDOUT, but to the currently
selected filehandle. That is they contain
print "Something\n";
and not
print STDOUT "Something\n";
In this case all you have to do is to select() a different
filehandle.
open OUT, '> '.$filename or die "Can't open $filename : $!\n";
{
my $oldfh = select(OUT);
call_the_procedure(params);
select($oldfh);
}
close OUT;
See
perldoc -f select
If the functions really write to STDOUT you may either:
{
local *STDOUT; # the "redirection" is only local
open STDOUT, '> '.$filename or die "Can't open $filename : $!\n";
call_the_procedure(params);
close STDOUT;
}
or
{
local *OLDOUT; # to store the STDOUT
open OLDOUT, '>&STDOUT' or die "Can't dup the STDOUT : $!\n";
close STDOUT;
open STDOUT, '> '.$filename or die "Can't open $filename : $!\n";
call_the_procedure(params);
close STDOUT;
open STDOUT, '>&OLDOUT' or die "Can't restore the STDOUT : $!\n";
}
The second would be necessary if the procedure executes some external
programs that need to be able to print to the same filehandle.
In either case make sure you restore the original STDOUT and/or
selected flehandle.
HTH, Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]