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.
#!/usr/local/bin/perl
sub numerically { $a <=> $b; }
open(I,"<data.txt");
chomp(@recs = <I>);
close I; # I've gone blind!
# reorder the array
foreach (@recs)
{
unless (/\w/) { next; }
my @f = split(/,/,$_);
my $str = join ',',$f[2],$f[0],$f[1],$f[3],$f[4];
push @ordered, $str;
}
@new_order = sort numerically (@ordered);
foreach (@new_order) { print "$_\n"; }
open(INPUT, "<input.txt") || die("Couldn't open input");
@data = <INPUT>;
close INPUT;
map(chomp,@data); # remove trailing \n from each rec
@sorted = sort byAge @data;
foreach $rec (@sorted)
($name, $addr, $age, $zip, $county) = split(/,/, $rec);
# print the recs here
}
exit 0;
sub byAge {
@a = split(/,/,$a);
@b = split(/,/,$b);
# age is the 3rd field (subscript = 2)
return $a[2] <=> $b[2];
}
1;