http://www.perlmonks.org?node_id=212009


in reply to Re: Re: creating an array of names
in thread creating an array of names

$i = 0; where 12 is the size of my array. and i is an index, or is there an al +ternative? while($i != 12){ if($month = $array[i]){ print "yes it's a month\n"; } }
Well first I'll assume the $array[i] is a typo. second you don't seem to be reading through the array. $i is set to 0 and thats not 12 of course so you will loop through the while forever and depending on wether $month contains jan, since $i is the first element in the array it will print "yes it's a month\n" again,and again, and again......etc

you could do it this way though
foreach my $item ($array) { print "its the month of $month\n" if ($month eq $array[$i]; }
I'm not sure if you're trying to find out if each element is a month or looking for one particular month. I just assumned you where looking for a particular month

Update: replaced '=' with correct eq in if statement

jjdraco
learning Perl one statement at a time.