This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
my $people = [ | |
{ first_name => 'Martry', last_name => 'McFly' }, | |
{ first_name => 'Emmett', last_name => 'Brown' }, | |
{ first_name => 'Biff', last_name => 'Tannen'}, | |
]; | |
print "sort by first name\n"; | |
foreach my $human (sort { $a->{first_name} cmp $b->{first_name} } @$people) { | |
print "$human->{first_name} $human->{last_name}\n"; | |
} | |
print "\n"; | |
print "sort by last name\n"; | |
foreach my $human (sort { $a->{last_name} cmp $b->{last_name} } @$people) { | |
print "$human->{first_name} $human->{last_name}\n"; | |
} | |
# sort by first name | |
# Biff Tannen | |
# Emmett Brown | |
# Martry McFly | |
# | |
# sort by last name | |
# Emmett Brown | |
# Martry McFly | |
# Biff Tannen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment