Hi, On 8/29/12, John W. Krahn <jwkr...@shaw.ca> wrote: > timothy adigun wrote: >> Hi, > > Hello, > >> On 8/29/12, timothy adigun<2teezp...@gmail.com> wrote: >> >>>> for(my $i=0; $i<= length(@startSite)-1; $i++) { >>> >>> The above could be: >>> for(my $i=0; $i<= scalar (@startSite); $i++) { >>> ... >> >> for(my $i=0; $i<= scalar (@startSite); $i++) { ## Oops >> >> for(my $i=0; $i<= scalar (@startSite)-1; $i++) { ## working > > First, length(@startSite) is WRONG so s/could/should/ and second, that > is usually written as: >
Agreed that length(@startSite) is WRONG and I didn't say otherwise, but not "scalar (@startSite)". If the OP decides to use C style of for loop, this is CORRECT: for( my $i=1; $i <= scalar (@startSite); $i++ ){ ... > for my $i ( 0.. $#startSite ) { The foreach keyword is actually a synonym for the for keyword, so one can use either. Please check this: http://perldoc.perl.org/perlsyn.html Note: foreach my $i (@startSite){...} will also do the same, except that in the "context" of the OP script, the array index is needed. -- Tim -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/