in reply to Re: Sorting within a file
in thread Sorting within a file
Thanks again...my @lines; { local *FILE; open(FILE, "< filename.in") or die("Couln't open input file: $!\n"); chomp(@lines = <FILE>); } my @sorted_lines = map { $_->[0]} sort ( $a->[1] <=> $b->[1] } map { [ $_, 0+$_ ] } @lines; { local *FILE; open(FILE, "> filename.out") or die("Couln't open output file: $!\n"); local $, = "\n"; print FILE (@lines); } Whats with the curly brackets? Here's what I have tried. It looks like + the file is already ordered alphabetically by id when I used "du -ks + *" but I need it by size which is the numbers. Here's my code, it do +esnt seem to change the order. #Push data into an array die("Cannot open Log file to read from.") unless(open(TAKE, "<unix_list.txt")); while ($line = <TAKE>) { push(@list_all, $line); } close(TAKE); @list_all = sort { $a <=> $b } @list_all; die("Cannot open Log file to write to.") unless(open(NEW, ">unix_list.txt")); print NEW @lines; close(NEW);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Sorting within a file
by ikegami (Patriarch) on Mar 04, 2005 at 20:45 UTC | |
by Anonymous Monk on Mar 04, 2005 at 20:54 UTC | |
by ikegami (Patriarch) on Mar 04, 2005 at 20:57 UTC |