#!/usr/bin/perl

@nums = map {rand} (1..10);

# Sort numerically, acending
@sorted = sort {$a <=> $b} @nums;
print join("\n", @sorted);
print "\n"x2;
$ans = <>;

# Sort numerically, decending
@sorted = sort {$b <=> $a} @nums;
print join("\n", @sorted);
print "\n"x2;
$ans = <>;

# sort lexically
@arr = qw(ACGT ACCTTAA AAACCGGAGATACGAAGG GCT CCTAA AAAA TATATA); 

@sorted = sort {$a cmp $b} @arr;
print join("\n", @sorted);
print "\n"x2;
$ans = <>;

@sorted = sort {length $a <=> length $b} @arr;
print join("\n", @sorted);
print "\n"x2;
$ans = <>;

@sorted = sort {($a =~ s/A/A/g) <=> ($b =~ s/A/A/g)} @arr;
print join("\n", @sorted);
print "\n"x2;
$ans = <>;

# Sort hashes
%hash = map {uc $_ => rand} qw(a h r q ee p aaa);

# Sort the keys
@sorted = sort {$a cmp $b} keys %hash;
print join("\n", @sorted);
print "\n"x2;
$ans = <>;

# Sort the values, report the keys
@sorted = sort { $hash{$a} <=> $hash{$b} } keys %hash;
print join("\n", @sorted);
print "\n"x2;
$ans = <>;

# Another way
foreach my $kk (sort { $hash{$a} <=> $hash{$b} } keys %hash) {
   print "Key=$kk, Value=$hash{$kk}\n";
}
print "\n"x2;
