Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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".


In reply to Use radio noise to make (non-critical) decisions... by dbush

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (5)
    As of 2020-03-31 03:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      To "Disagree to disagree" means to:









      Results (179 votes). Check out past polls.

      Notices?