LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-04-2007, 04:28 PM   #1
americanforest
LQ Newbie
 
Registered: Sep 2007
Posts: 19

Rep: Reputation: 0
Perl Output


I have a perl script which I run like so:

perl_sript < input_text_file

The script formats the text and prints it out in the shell. How can I get the script to write its output (what it writes out in the shell) to a new file.

Sorry if its obvious but I'm a noob.
 
Old 11-04-2007, 04:47 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,119

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
The "<" you used redirects the input (STDIN) for your code; ">" does likewise for output (STDOUT).
Try playing with that and see how you go.
 
Old 11-04-2007, 05:15 PM   #3
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Using re-direction like syg00 said, or in your program, assuming you are using print statements, you can do something like this:
Code:
#!/usr/bin/perl

open(OUTPUT, ">somefile") || die "cannot open somefile for writing : $!";

print OUTPUT "whatever you want to output\n";
...

close(OUTPUT);
 
Old 11-04-2007, 05:18 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
save this example code
Code:
while (<>) {
 print ;
}
and run it on the shell prompt like : perl myscript < file > outfile. Here i use shell's redirection to create the output file. You can also create the output file inside Perl script, by using open and redirection operator as well
perldoc -f open for more info
 
Old 11-04-2007, 10:34 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
For 'or' vs '||' see here: http://www.developertutorials.com/tu...616/page1.html
 
Old 11-05-2007, 05:38 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
generically

script < input_text_file > output_file
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl Dumping output into logfile. misconfiguration Programming 6 08-10-2007 02:19 AM
Perl: Not all output is captured by backticks Poetics Programming 2 07-31-2007 03:40 PM
Output to /dev/tty9 (perl) jrbush82 Programming 1 12-27-2006 01:53 PM
want perl to output shell commands verbose selgan Programming 2 02-19-2006 03:44 PM
Problem in output to a process in perl saneax Linux - Software 2 08-31-2004 06:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration