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);

In reply to Re: Can scalar representation cause infinite loops? by ikegami
in thread Can scalar representation cause infinite loops? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.