in reply to Re: Avoiding repeated undefs
in thread [Solved] Avoiding repeated undefs

even if the array is presized

If you specify the slice in the assignment it's fine though:

use strict; use warnings; use Test::More tests => 1; $_ = "Anyway I suspect you cannot avoid them repeated: you are are in +left side"; my @undef; my ($key, $val); ($key, @undef[0..4], $val) = split(/\s+/, $_); is ($val, 'them');

I still prefer Eily's approach, however.

Replies are listed 'Best First'.
Re^3: Avoiding repeated undefs
by rsFalse (Chaplain) on Feb 28, 2019 at 00:15 UTC
    Similar approach:
    ( my $key, (undef) x 5, my $val) = split(/\s+/, $_);
    Note: 'undef' must be enclosed with parentheses to force list context for 'x' operator.