By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,670 Members | 1,526 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,670 IT Pros & Developers. It's quick & easy.

Perl output to a file

P: 5
Hai there i have a perl code as follows


Expand|Select|Wrap|Line Numbers
  1.  open(DATA1,'blastout');
  2. while(<DATA1>)
  3.  
  4.  {
  5.    my @data = split /\t/,$_;
  6.    print "@data\n" if $data[3]>=$ln;
  7. }
  8.  
i want to save this printed data into a file
Sep 19 '16 #1
Share this Question
Share on Google+
4 Replies


Expert Mod 100+
P: 589
Ok, you already know about the open and print functions, so what's stopping you?
Sep 19 '16 #2

P: 5
Am new to programme i tried different way but i couldn't make it
Sep 20 '16 #3

P: 5
Expand|Select|Wrap|Line Numbers
  1. open(DATA1,'blastout');
  2. while(<DATA1>)
  3.  
  4.  {
  5.   open (OUTFILE, ">upcase");    
  6.   my @data = split /\t/,$_;
  7.   print OUTFILE $_ if $data[3]>=$ln;
  8.    }
  9.  
I tried this way but there is nothing outputted on upcase file
Sep 20 '16 #4

Expert Mod 100+
P: 589
Expand|Select|Wrap|Line Numbers
  1. open (OUTFILE, ">upcase");
That needs to be before the while loop and you should add error checking.

Expand|Select|Wrap|Line Numbers
  1. open(DATA1,'blastout');
  2. open (OUTFILE, '>', 'upcase') or die "failed to create 'upcase' <$!>";
  3.  
  4. while(<DATA1>) {  
  5.   my @data = split /\t/, $_;
  6.   print OUTFILE $_ if $data[3] >= $ln;
  7. }
  8.  
Sep 20 '16 #5

Post your reply

Sign in to post your reply or Sign up for a free account.