in reply to Group array in threes

This sounds like homework. Do yourself a favor and try to solve it yourself, otherwise your next test or exam will be a disaster. I'll give you two hints: Use a loop and take a look at the shift() function

Replies are listed 'Best First'.
Re^2: Group array in threes
by joec_ (Scribe) on Feb 02, 2009 at 13:24 UTC
    Homework - i wish! What the array actually contains is molecular statistics and pharmacokinetic results.

    If (and it may in future) contain references how can i print those and not ARRAY(0x860be48) etc?

    Thanks

      Here is a simple solution with arrayref and one that can cope with array sizes not having multiples of threes

      my $array= [1,2,3,4,5]; while (@$array) { push my @r, shift @$array if (@$array); push @r, shift @$array if (@$array); push @r, shift @$array if (@$array); print join(',',@r),"\n"; }