Thread: small error..
View Single Post
Old Jun 14th, 2007, 2:03 AM   #6
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,464
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Lets take a random stab in the dark and assume he wants to print out the contents of the month array accessing one element at a time. If this is not what you want, elaborate.

#!/usr/bin/perl

print "The months of the year are: \n";
@months = ("January", "Febuary", "March", "April", "and so on...");
for ($i = 0; $i < 5; $i++) 
{
        print "$months[$i]\n";
}

On a side note, why even include a newline in the values of the array? This is more of a formatting option than it is part of the data... so imho, its best left for the print statement to handle.

On another side note, why even care how many elements the array has when printing it, if you are going to print them all anyway... do this:

#!/usr/bin/perl

print "The months of the year are: \n";
@months = ("January \n", "Febuary \n", "March \n", "April \n", "and so on... \n");

foreach $myMonth (@months)
{
        print "$myMonth\n";
}
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote