Thread: small error..
View Single Post
Old Jun 15th, 2007, 7:08 PM   #7
teishu
Programmer
 
Join Date: May 2006
Posts: 49
Rep Power: 0 teishu is on a distinguished road
Quote:
Originally Posted by Infinite Recursion View Post
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";
}
yeh, thats what i was trying to do... im just learning the basic syntax at the moment...
__________________
Intel Pentium M 1.73Ghz -- Sony Vaio -- 1024MB Ram -- Ubuntu 8.04
AMD Athlon X2 4200+ -- Asus V3-M2V890 -- 2GB Kingston -- Vista Ultimate 32bit
Intel C2D E4400 -- 2048MB GeIL - Windows XP SP2

ASCII stupid question, get a stupid ANSI !
teishu is offline   Reply With Quote