Ever had the problem of not knowing what to do? Perl and random.org to the rescue...
use strict; use warnings; use LWP::Simple; my ($szConumdrum, $szThisSolution, @solution, $URL, $iRandom); print 'Conundrum: '; chomp ($szConumdrum = <STDIN>); while () { print 'Solution: '; chomp ($szThisSolution = <STDIN>); last if $szThisSolution eq ''; push @solution, $szThisSolution; } $URL = "http://www.random.org/cgi-bin/randnum?num=1&min=0&max=$#soluti +on&col=1"; print "Deciding...\n"; $iRandom = get($URL); die "Unable to decide!\n" if not defined $iRandom; print "The solution to '$szConumdrum' is '$solution[$iRandom]'\n"; __END__
I was in two minds about posting this code and so I thought I would ask the script itself. The following is honestly the result...
Conundrum: Should I post this code to PM? Solution: Yes Solution: No Solution: Deciding... The solution to 'Should I post this code to PM?' is 'Yes'
The ether can't be wrong.
Cheers,
Dom.
Update: Changed the code based on jdporter's suggestion in the chatterbox; "you should probably use $#solution, rather than @solution - 1. And you can interpolate it directly".
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Use radio noise to make (non-critical) decisions...
by jdporter (Paladin) on Jan 08, 2003 at 15:46 UTC | |
by dbush (Deacon) on Jan 08, 2003 at 20:02 UTC | |
Re: Use radio noise to make (non-critical) decisions...
by insensate (Hermit) on Jan 09, 2003 at 03:25 UTC | |
by Aristotle (Chancellor) on Jan 11, 2003 at 20:28 UTC | |
Re: Use radio noise to make (non-critical) decisions...
by BrentDax (Hermit) on Jan 10, 2003 at 03:33 UTC |
Back to
Cool Uses for Perl