Functions


The Little Engine That Could

          #!perl

$i = 0;
$n = 5;

while ($i < 10) {
print "I am about to call my subroutine...\n";
&goofy;
print "Called it!\n";
$i++;
}

print "The value of variable n is $n\n";
print "BYE!\n";

sub goofy {
print "Hi, I'm goofy.\n";
$n += 5;
}

A Useful Built-in (or 2, or 3...)

     #!perl

@dogs = qw(Baxter Opie Chaico Lassie Rover);
$i = 0;

while ($i<20) {
$random_array_index = int(rand(scalar(@dogs)));
print "I pick $dogs[$random_array_index]\n";
$i++;
}