-
-
Save yko/1295774 to your computer and use it in GitHub Desktop.
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 %hash; | |
# Fill %hash with 20 random values 0 - 99 | |
for (1 .. 20) { | |
my $rand = int(rand(100)); | |
$hash{$rand} = $rand; | |
} | |
my @sorted = sort { $hash{$a} <=> $hash{$b} } keys %hash; | |
print "\nv1\n"; | |
foreach my $key (@sorted[0..9]) { | |
print $hash{$key} . "\n"; | |
} | |
print "\nv2\n"; | |
# Note, splice damages @sorted array | |
foreach my $val (splice(@sorted, 0, 10)) { | |
print $val . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment