Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: save output of program in another file

by perlfan (Curate)
on Jun 06, 2013 at 16:49 UTC ( #1037488=note: print w/replies, xml ) Need Help??

in reply to save output of program in another file

3 argument open or print to STDIN and redirect to a file at the commandline.
  • Comment on Re: save output of program in another file

Replies are listed 'Best First'.
Re^2: save output of program in another file
by bingalee (Acolyte) on Jun 06, 2013 at 17:07 UTC
    um could you plz correct this?
    open(IN,"100.fastq"); open(OUT,">100-out.fastq"); while($raw=<IN>) { print $raw; $raw=~s/\n|\r//g; @inf=split(//,$raw); for($i=0;$i<scalar(@inf)-15;$i++) { print $inf[$i]; } print "\n"; <>; } close (OUT); close(IN);
    what do i do in the command line? did i do it right?

      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


        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


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1037488]
[Cosmic37]: when slurping one can undef the record separator thingy; but presumably one should redefine it afterwards? how?
[Cosmic37]: I'm wondering whether there is a specific/(or at least "usual") command or does one take a copy before undefining and then copy it back after slurping file into a string?
[BarApp]: I need help accessing perl files. I need permission!!!
[Cosmic37]: I wish thee a peachy life and express gratitude for considering my pathetic questions
[erix]: record separator

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2017-06-29 16:33 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (672 votes). Check out past polls.