Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

jjdraco
learning Perl one statement at a time.


Comment on Re: Re: Re: creating an array of names
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2015-07-07 23:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls