Skip to content

Instantly share code, notes, and snippets.

@adeolaawoyemi
Created December 10, 2010 15:38
Show Gist options
  • Save adeolaawoyemi/736348 to your computer and use it in GitHub Desktop.
Save adeolaawoyemi/736348 to your computer and use it in GitHub Desktop.
select random window (or item from hash)
#!/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