[oak perl] until loop(s)

David Alban extasia at gmail.com
Mon Mar 28 13:27:22 PST 2005


If you have:

  my $counter;
  until ( $counter == 5 ) { ... }

Then (at least) the first time $counter is tested by the until loop,
you're asking perl to compare the number five to $counter, which is
undefined because it never was assigned a value.

If you first initialize $counter:

  my $counter = 0;
  until ( $counter == 5 ) { ... }

then unless you undefine (or some operation undefines) $counter in the
loop, you'll never be comparing a number to an undefined value.

TMTOWTDI.  I might have done your loop as:

  for my $counter ( 1..5 ) {
    ...
  }

if $counter wasn't needed after the loop and:

  my $counter;
  for $counter ( 1..5 ) {
    ...
  }

if $counter was needed after the loop.

On Mon, 28 Mar 2005 16:03:56 -0500, Sandy Santra <santranyc at yahoo.com> wrote:
> OK.  No, I don't know how to solve that; I still get that error.

-- 
Live in a world of your own, but always welcome visitors.


More information about the Oakland mailing list