Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: how to extract script output in new text file ?

by Loops (Curate)
on Oct 25, 2014 at 17:31 UTC ( [id://1104991]=note: print w/replies, xml ) Need Help??


in reply to how to extract script output in new text file ?

Hi Chris202 and welcome to the monastery.

You can use an open command very similar to the one that already exists in your program, except switching the less-than to a greater-than symbol to indicate output. Then use the Perl select command to indicate that you want print output to go there instead of STDOUT (which is usually the console).

use strict; use warnings; open (my $output, '>', 'output.txt') or die "cannot open > output.txt +$!"; select $output; open (my $file, '<', 'file.txt') or die "cannot open < file.txt $!"; while (<$file>) { print unless (/^A/) } select *STDOUT; print "All Done.\n";

The print unless ... idiom in the example above is a more terse way to write the same thing you had in your program.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-23 15:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found