Hello experts!
I've been writing scripts to answer biological questions in evolutionary genomics for just over a year and have recently come across a rather strange problem involving STDOUT.
To write my data to an output file, I have written a subroutine so that I can print to several outfiles without having to create a filehandle for each. It also saves on space
sub output2file {
my($OUT, $printout) = @_;
open (OUT, ">>$OUT"
;
print OUT "$printout";
close (OUT);
}
I appended this subroutine to my perl template several months ago (so it's present in all my scripts), which enables me to print out like so:
output2file("outfile.txt", "$results"
;
I can run a second script ('script2.pl') from 'script1.pl' using backticks (although using system and exec makes no difference):
`perl script2.pl some_arguements`;
However, '$results' (the result of running 'script2.pl'), is printed to STDOUT instead of being printed to the outfile.
# running other script2s using backticks creates output files
# running 'script2.pl' from the command line creates an outfile, but this is no longer the case after 'script1.pl' has been invoked (therefore it can't be a bug/typo)!
Would Perl print to STDOUT as a default if an exception was returned in 'script2.pl'? I use warnings, so surely it would warn me if this were so! Besides, my $results from STDOUT look correct! What is stopping 'script2.pl' from printing $results to the outfile?
Thanks in advance for any help that you can give,
J. Chamary
(version 5.8.0, using -w, XPpro).
I've been writing scripts to answer biological questions in evolutionary genomics for just over a year and have recently come across a rather strange problem involving STDOUT.
To write my data to an output file, I have written a subroutine so that I can print to several outfiles without having to create a filehandle for each. It also saves on space
sub output2file {
my($OUT, $printout) = @_;
open (OUT, ">>$OUT"
print OUT "$printout";
close (OUT);
}
I appended this subroutine to my perl template several months ago (so it's present in all my scripts), which enables me to print out like so:
output2file("outfile.txt", "$results"
I can run a second script ('script2.pl') from 'script1.pl' using backticks (although using system and exec makes no difference):
`perl script2.pl some_arguements`;
However, '$results' (the result of running 'script2.pl'), is printed to STDOUT instead of being printed to the outfile.
# running other script2s using backticks creates output files
# running 'script2.pl' from the command line creates an outfile, but this is no longer the case after 'script1.pl' has been invoked (therefore it can't be a bug/typo)!
Would Perl print to STDOUT as a default if an exception was returned in 'script2.pl'? I use warnings, so surely it would warn me if this were so! Besides, my $results from STDOUT look correct! What is stopping 'script2.pl' from printing $results to the outfile?
Thanks in advance for any help that you can give,
J. Chamary
(version 5.8.0, using -w, XPpro).