Skip to content

Instantly share code, notes, and snippets.

@masak
Created February 12, 2009 17:22
Show Gist options
  • Save masak/62746 to your computer and use it in GitHub Desktop.
Save masak/62746 to your computer and use it in GitHub Desktop.
$ cat test.pl
my $a = join "", <>;
print "\n";
$h = {
'thing1' => { 'Namespaces' => [ qw<b d f> ] },
'thing2' => { 'Namespaces' => [ qw<a c h> ] },
};
for (map { $h->{$_}{Namespaces}[0] } keys %{$h}) {
print $_;
print "\n";
}
# Sort alphabetically on the first namespace
sub by_namespace {
$h->{$a}{Namespaces}[0] cmp $h->{$b}{Namespaces}[0];
}
my @managers = sort by_namespace keys %{$h};
for (@managers) {
print $_, "\n";
}
$ perl test.pl
^D
b
a
thing1
thing2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment