Created
December 10, 2010 15:38
-
-
Save adeolaawoyemi/736348 to your computer and use it in GitHub Desktop.
select random window (or item from hash)
This file contains hidden or 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
#!/opt/local/bin/perl | |
use strict; | |
use warnings; | |
use Data::Dumper; | |
my @windows = qw/one two three four/; | |
my %windows = map { $_ => $_ } @windows; | |
print Dumper \@windows, $/; | |
print Dumper \%windows, $/; | |
&get_random_window(); | |
sub get_random_window { | |
my $count = scalar @windows; | |
my $index = int(rand($count)); | |
print "We have $count windows to choose from$/"; | |
print "we have chosen window ", $index+1, $/; | |
print "NAME: ", $windows[$index], $/; | |
print "TITLE: ", $windows{$windows[$index]}, $/; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment