in reply to Long array -> multiple columns?

Your code is much more complicated than it need to be.

It helps to write a function that prints the array in a defined number of columns:

sub print_in_n_cols { my ($count, @items) = @_; while (@items){ for (1 .. $count){ print "\t", shift @items; last unless @items; } print "\n"; } }

Now you can call that, based on the number of dupes:

if (@dupes <= 10){ print_in_n_cols(1, @dupes); } elsif (@dupes <= 20){ print_in_n_cols(2, @dupes); } ...

Actually I don't why you want this behaviour, it feels more natural to me to always print in four columns - but of course that's your choice.

Replies are listed 'Best First'.
Re^2: Long array -> multiple columns?
by ikegami (Patriarch) on Jan 30, 2008 at 06:53 UTC
      That's exactly the issue I had when I tried to approach it the first time by just popping/shifting stuff off like the subroutine above..