[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] A major screw-up: infinite loop



> $upper = 2048;
> for  ($i = 1; $i <= $upper; $i ++) {
>    $date = &getadatestringfromsomewhere();
>    $my_date = &parseDate($date); # return a different date format
> }

Hazard my guess. The space between $i and ++ means that $i will never
get incremented in the above for loop. The parseDate routine is using
$i to do some kind of iteration through the 12 months. Since $i is
global (not declared with "my"), it is left to be 13 after the end of
some loop in parseDate (it goes to 13 to make the conditional
'$i <= 12' false).

This is a good reason why you should either scope all variables to
a specific package or make them lexically scoped using "my". That
and always have "use strict" on. Oh, and don't cram the whole program
into one line (which is not the case with this program, but I see that
far too often on this list. Is whitespace really that evil?).

Kevin

-- 
------------------------------------------------------------
 keViN cUReToN - ProDuCtiOn EnGiNeEr - SoFtWArE DeVElOpmEnT
  (650)846-8388       kevinc@pdi.com    http://www.pdi.com
  <<- Madness takes its toll, please have exact change ->>

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe