#!/usr/bin/perl
$a=5;
+ # Here we make a new variable called "a" to use as a simple loop co
+unter.
+ # Now, we'll create some arrays, and start them off with some fresh
+ elements.
@group=("swarm","heap","load","gang","squad","bunch","cluster","family
+","team"); # This is an array, called group. Arrays are designated wi
+th in at-symbol (@) prefix.
@adjective=("crack-smoking","supple","furious","sexy","hyperactive","i
+nquisitive","hot","old","crazy");
@noun=("midgets","Cuban refugees","clowns","bitches","programmers","ba
+bies","dogs","hep-cats","apes");
while($a>0)
+ # This is a simple while-loop construct. It uses the same syntax as
+ Java, or C,
{
+ # with one exception...You need to enclose even singular expression
+s in braces.
$index=rand(9);
+ # This generates a random integer between 0 and 9, and stores it in
+ $index
print( "\nMr. T says, \"Daaaaammmn!!! A @group[$index]");
+ # First part of the line is printed here, in this statement.
$index=rand(9);
+ # A new number is generated, and stored in $index.
print( " of @adjective[$index]");
+ # The n'th element ($index) of the array is printed here.
$index=rand(9);
+ # A new random number is generated and stored in $index.
print( " @noun[$index] just ate my balls!!\"");
+ # The end of the line is printed.
$a--;
+ # Our loop counter is decremented here, and the loop iterates.
}
print("\n\n");
+ # Toss in a few newlines to keep things pretty, and we're all done!
-
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.