use strict; use warnings; 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 { /^(\d+)/ && [ $_, 0+$1 ] } # OR: map { no warnings; [ $_, 0+$1 ] } @lines; { local *FILE; open(FILE, "> filename.out") or die("Couln't open output file: $!\n"); local $, = "\n"; print FILE (@sorted_lines); }
Update: Fixed a warning.
In reply to Re: Sorting within a file
by ikegami
in thread Sorting within a file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |