in reply to Filling an array

It is not polite to push others, but arrays are an exception:

my @arr = ();

for ($i=1; $i=100; $i++)
{ push(@arr,1);
}

Replies are listed 'Best First'.
Re: Re: Filling an array
by blakem (Monsignor) on Sep 07, 2001 at 11:35 UTC
    Turn on warnings with that code.... I think you'll find a critical (but easy to make) bug in the above code.

    -Blake

Re: Re: Filling an array
by Anonymous Monk on Sep 07, 2001 at 17:07 UTC
    Doh, you are correct. I changed usually use for loop code like this:

    for ($i=0; $<100; $i++) { push(@arr,1); }

    but that was before I knew about the CODE tags, so I figured it would be easier to just change it to an equal sign. I forgot you needed two of them :)
      I like this style of for loop, since there are fewer
      chances for a typo:
      push(@array,1) for(0..99);

      And you can incorporate the multiplier with your push:
      push(@array, $_ * 3) for(0..99);

      -blyman