in reply to Syntactically cool list of lists

At the cost of a temporary counter variable

my $c = -$l; push @b, [ grep {defined $_} @a[($c+=$l)..($c+$l-1)] ] for 0 .. $#a/$l

if you don't mind extending @a to a multiple of $l ;-)

<update>
Oops - almost identical to JohnGG's solution above - and his uses $_ as counter. hrm :-/

push @b, [ grep {defined $_} @a[$_*$l .. ($_*$l+$l>$#a ? $#a : $_*$l+$ +l-1)] ] for 0 .. $#a/$l;

This one doesn't extend @a. But readable, well... it's the best I can contrieve in a single line (up to ";" that is).

</update>

--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: Syntactically cool list of lists
by johngg (Canon) on Dec 21, 2006 at 11:28 UTC
    I can't claim it was my solution, just a refinement of sgifford's :)

    Cheers,

    JohnGG