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".
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|