CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [francy87] writing array element in a file: Edit Log



Chris Charley
User

Apr 26, 2013, 12:39 PM


Views: 1347
Re: [francy87] writing array element in a file

This will print the sorted numbers to output file 'o44.txt'.

Code
 #!/usr/bin/perl  
use strict;
use warnings;

my $file = 'rep_set_ass_tax.fna';
open my $fh, '<', $file or die "Unable to open $file for reading. $!";

my $data;
do {local $/; $data = <$fh>}; # slurp the entire file

close $fh or die "Unable to close $file. $!";

my $output = 'o44.txt';
open my $out, '>', $output or die "Unable to open $output for writing. $!";

print $out join("\n", sort {$a <=> $b} $data =~ /\d+/g), "\n";

close $out or die "Unable to close $output for writing. $!";

Update: It looks like rep_set_tax_ass.fna aws created on a Mac by the '\r' line endings. I don't know how to fix this so your program will run.


(This post was edited by Chris Charley on Apr 26, 2013, 12:49 PM)


Edit Log:
Post edited by Chris Charley (User) on Apr 26, 2013, 12:49 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives