Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Re: Re: creating an array of names

by jjdraco (Scribe)
on Nov 11, 2002 at 18:13 UTC ( #212009=note: print w/replies, xml ) Need Help??

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

learning Perl one statement at a time.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://212009]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2017-11-21 03:06 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (295 votes). Check out past polls.