in reply to Why doesn't this for loop work like I expect?

Change it to a while loop:
while (@files) { ...
That should fix your problem, cause it'll only loop as long as there are elements in @files. Whereas yours was actually looping *over* @files, which is a different thing, and not recommended if you're going to be modifying @files (which you did, by using shift).

Alternatively, though, you may want to try using splice:

push @data, [ splice @files, 0, $num_cols ] while @files;
splice grabs chunks of an array (and can also replace those chunks w/ a list) and increases/decreases the size of the array as necessary. Sounds good for your particular use.

Replies are listed 'Best First'.
RE: Re: Why doesn't this for loop work like I expect?
by takshaka (Friar) on May 18, 2000 at 00:44 UTC
    Bah. btrott beat me to the splice. Here's a silly way to do it: @data = map [splice @files, 0, $num_cols], 0..@files/$num_cols;
RE: Re: Why doesn't this for loop work like I expect?
by husker (Chaplain) on May 18, 2000 at 16:54 UTC
    I am enlightened! I like this method over the while loop too, because with the while loop, if the $#files wasn't an integer multiple of $num_cols, then I'd get null links on the last row of my table. It displays correctly, but it's still not "correct". Using the splice operator fixed that too.