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

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



On Mon, Jul 31, 2000 at 11:42:14AM -0400, Paul King wrote:
> > Oh, parseDate set $i to 12, and it was incremented to 13 by the for loop.
> > 12 does make more sense in a function called parseDate.  :)
> >
> > Ronald
> 
> I was pretty picky about this question, because on the face of it the problem
> looks very simple. A global variable $i was "clobbered", as some have said,
> by dateParse. But I wanted you to go a little beyond that. Why 13? Why not
> some other number? And it looksas if Ronald has come the closest. It has to
> do with ParseDate, which has an associative array of months, of which
> there are 12. The $i that is in that function loops through the months. When
> it exits, the calling routine always increments 12 to 13.


Several things:

  * Date::Manip doesn't have a function parseDate, it's ParseDate.
  * Date::Manip uses "use strict;", and the only part that is 
    "no strict 'vars';" doesn't use $i.
  * In order for Date::Manip to clobber $i, $i has to be a package
    variable *and* be in the same package. All Date::Manip routines
    are in the package Date::Manip, and I cannot find any occurance
    of a fully qualified name for $i in Date/Manip.pm.
  * The sub ParseDate in Date::Manip doesn't use a variable $i, nor
    does it loop over an associative array.
  * ParseDate calls ParseDateString to do much of the parsing. In
    ParseDateString, the variable $i is my-ed.
  * How do you use a counter to loop over an associative array anyway?
  * Grepping over Date::Manip shows that all uses of $i are lexical.
  * perl -MDate::Manip -wle 'for ($i = 0; $i < 100; $i ++) {
    $foo = &ParseDate ("today")} print $i' prints 100.


Abigail

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