Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Output to STDOUT and print last line to console

by Loops (Curate)
on Oct 24, 2014 at 05:04 UTC ( [id://1104832]=note: print w/replies, xml ) Need Help??


in reply to Output to STDOUT and print last line to console

The problem is that your final print statement is being sent to the end of output.txt instead of the console. STDOUT is still redirected at that point. There are several ways to remedy the situation; here is one using backticks (`) to capture the output of the script you run:

use Fcntl; use Tie::File; open my $out, ">", "output.txt" or die "$0: open: $!"; my $run = "./SCRIPT.pl"; print $out "##Start of SCRIPT.PL##\n", `$run`; close $out; tie my @rows, 'Tie::File', 'output.txt', autochomp => 0 or die "error: + $!\n"; print ":$rows[-1]";

In the above case there is no pressing need to use Tie::File which will be less efficient. Hopefully this was just a small snippet of a larger work where its use is more warranted. :o)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1104832]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-25 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found