Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
open IN, "test.txt" or die "IN: $!";
# since you have to sort the lines
# you need them all read into an array
my @lines = <IN>;
close(IN);
# Pull off field headers and save for output
my $fields = shift @lines;
# Efficient sorting method
my @sorted =
map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [ $_ , (split)[1] ] } @lines;
open OUT, "> sorted.txt" or die "OUT: $!";
# print lines to new file, including the header fields
print OUT for $fields, @sorted;
close (OUT);
@unnamed_array = ( [ "abc1 20 city1", 20 ],
[ "abc2 15 city2", 15 ],
[ "abc3 45 city3", 45 ],
[ "abc4 19 city4", 19 ],
);
my @sorted = sort { (split /\s+/, $a)[1] <=> (split /\s+/, $b)[1] } @lines;