Code: Select all
#!/usr/bin/perl
print "usage:
sortbylenght.pl <file_to_sort.txt> file_to_save.txt";
@list = <>;
sub sortIt {
length($a) <=> length($b);
}
foreach $curr (sort sortIt (@list)) {
$curr =~ s/[\n\r]//g;
print "$curr\n";
}
Code: Select all
#!/usr/bin/perl
print "usage:
sortbylenght.pl <file_to_sort.txt> file_to_save.txt";
@list = <>;
sub sortIt {
length($a) <=> length($b);
}
foreach $curr (sort sortIt (@list)) {
$curr =~ s/[\n\r]//g;
print "$curr\n";
}