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

Re^3: save output of program in another file

by blue_cowdawg (Prior)
on Jun 06, 2013 at 19:58 UTC ( #1037507=note: print w/ replies, xml ) Need Help??


in reply to Re^2: save output of program in another file
in thread save output of program in another file

What environment are you running in? "Command line" is pretty vague.

A few pointers here:

use strict; use warnings;
is a great way to start a script in Perl since without them Perl won't complain much about what you are doing other than gross syntax errors. With the strictures in place you get told about more subtle issues that can help you get your code working the way you expect it to.
open THING,"<some_file.ext" or die "some_file.ext:$!"; open OTHERTHING,">some_other_file.ext" or die "some_other_file:$!";
In my humble opinion the one of the ten commandments of programming in any language is "Thou Shalt Catch Errors." Catching errors is another great step towards programming nirvana where you code does what you expect. There could very well be permission issues either reading a file or writing a file. Your code may not be executing where you think it is. All this and more can cause you issues.

Finally: what are you expecting your code to do in the first place? What does your input look like?


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg


Comment on Re^3: save output of program in another file
Select or Download Code
Re^4: save output of program in another file
by bingalee (Acolyte) on Jun 06, 2013 at 20:55 UTC

    Hi!

    my program worked when I changed it to .print OUT "$inf[$i]"

    Some one told me I could redirect the output in the terminal.So I was wondering if i could do that there. I'm using linux-well ubuntu really

    And finally

    href=http://perlmonks.org/index.pl?node_id=1037465

    thats what I have been trying to do since morning:)

      To redirect the standard output, change how you run the program.:
      # Without redirection: ./myscript.pl # With redirection: ./myscript > output.txt
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
          Some one told me I could redirect the output in the terminal.

      To underscore what choroba said:

      $ ./myscript.pl > somefile.txt # create new/overwrite file # ./myscript.pl >> somefile.txt # append to a file # ./myscript.pl 2>&1 > somefile.txt # stdout and stderr to a file # ./myscript.pl | less # stdout to stdin of a program
          I'm using linux-well ubuntu really And finally
      Ubuntu is a distribution of Linux from the Debian family of Linux distros.


      Peter L. Berghold -- Unix Professional
      Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2014-08-22 09:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (152 votes), past polls