in reply to sorting an array

A better way might be
while (@online) { push @links1, shift @online; push @links2, shift @online; push @links3, shift @online; }

or as per bart's idea of using an array of anonymous arrays (see perlref)

while (@online) { push (@{$links[$_]}, shift @online) for 0..2; }
To access the 2nd element (index 1) in the 3rd sub-array (index 2) you would use
$var = $links[2]->[1];

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: sorting an array
by Anonymous Monk on Apr 07, 2007 at 14:14 UTC
    That's really interesting, thanks very much. I've proved to myself it works by using the following:
    while (@online) { push (@{$links[$_]}, shift @online) for 0..2; } @links1 = @{ $links[0] }; @links2 = @{ $links[1] }; @links3 = @{ $links[2] }; print "@links1<br>@links2<br>@links3";
    I shall try to work with the anonymous arrays going forward rather than the named ones but it does all start to get rather obscure and difficult for a simpleton such as me...
      I remember I had a hard time trying to grok references, creating references and dereferencing. But I got through it, and so will you. And you have to, since references are a crucial concept in perl5.

      Cheers from another simpleton,

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}