Hi all
I'm trying to think of the best way to write a script that can either output to a file or to STDOUT if no file name is supplied.
For example,
would send the output to a file but
would just print to the screen.
Inside script.pl I was thinking of something along the lines of
but is this the right idea? What if I close OUT - is this "impolite" since it might be going to STDOUT
Any comments or improvements on my idea are very welcome
Thanks
~ Michael
I'm trying to think of the best way to write a script that can either output to a file or to STDOUT if no file name is supplied.
For example,
Code:
script.pl -o file.txt
Code:
script.pl
Inside script.pl I was thinking of something along the lines of
Code:
if ( $OUTFILE ) {
open OUT, $OUTFILE
}
else {
OUT = *STDOUT
}
# Print to file or screen, depending on whether $OUTFILE is set
print OUT "Hello world\n";
Any comments or improvements on my idea are very welcome
Thanks
~ Michael