in reply to Can scalar representation cause infinite loops?
length($a) lt 2 should be length($a) < 2. You are converting the returned length to a string and doing a lexical (not a numerical) compare.
$a = "abcdefghij"; length($a) lt 2 ==> "10" lt "2" ==> true $a = "0$a"; length($a) lt 2 ==> "11" lt "2" ==> true ... $a = "0$a"; length($a) lt 2 ==> "20" lt "2" ==> false
If length($a) starts in [0..1], the final length($a) will be 2.
If length($a) starts in [2..9], $a won't change.
If length($a) starts in [10..19], the final length($a) will be 20.
If length($a) starts in [20..99], $a won't change.
If length($a) starts in [100..199], the final length($a) will be 200.
If length($a) starts in [200..999], $a won't change.
If length($a) starts in [1000..1999], the final length($a) will be 2000.
If length($a) starts in [2000..9999], $a won't change.
If length($a) starts in [10000..19999], the final length($a) will be 20000.
etc.
This could cause thrashing with very long strings (which localtime doesn't return), but I don't see this ever creating an infinite loop.
Try using
my $min = (localtime)[1]; $min = sprintf('%02d', $min);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can scalar representation cause infinite loops?
by Anonymous Monk on Jul 19, 2007 at 22:20 UTC | |
|
Re^2: Can scalar representation cause infinite loops?
by Anonymous Monk on Jul 19, 2007 at 22:22 UTC |