Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Avoiding repeated undefs

by hippo (Bishop)
on Feb 26, 2019 at 10:08 UTC ( [id://1230553]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1230553]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-25 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found