Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Ballsy coding

by Anonymous Monk
on Apr 20, 2000 at 20:42 UTC ( [id://8189]=note: print w/replies, xml ) Need Help??


in reply to "Ate My Balls" Syntax Generator

Your script works as advertised, and the fact that it's wordier than necessary is obviously deliberate, so that beginners can follow it more easily. The one problem I *do* have with it is that there is no-reason to hard-code to number of elements in each list. Much better to use the $# construct to return the size of the list. In other words:
print "@groups[rand($#groups + 1)]\n";
will work even if you add or remove members from @groups.

Replies are listed 'Best First'.
RE: Ballsy coding
by Anonymous Monk on Apr 20, 2000 at 20:44 UTC

    Whoops, I'm new here and didn't realize comments were html-ized. That line of code should read:

    print "@groups[rand($#groups + 1)]\n";

    That is all.

      Hmm, even shorter to say: print $groups[rand(@groups)], "\n"; Did the OP mean to take an array slice?

      Or rather:

      print "@groups[rand($#groups + 1)]\n";

      Phew, a "preview post" button would've helped though...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://8189]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found