Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Re: creating an array of names

by jjdraco (Scribe)
on Nov 11, 2002 at 18:13 UTC ( [id://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

jjdraco
learning Perl one statement at a time.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://212009]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (8)
As of 2024-04-18 08:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found