in reply to Avoiding vivification with array slice

You could modify the line in question like this:

@b = grep { defined $_ } @{[ @a[0..5] ]};

Or even:

@b = grep { defined $_ } @{[@a]}[0..5];

But whatever approach you choose, make sure that you comment it so it's clear why you do it.

Replies are listed 'Best First'.
Re^2: Avoiding vivification with array slice
by jbert (Priest) on Sep 09, 2008 at 13:45 UTC

    Ah, this is cool. An anonymous copy, dereferenced on the spot.

    And, as you say, definitely comment-worthy.

    Thanks