in reply to Store result of split directly to variable(s)

Hello Perl_Ally,

Here are two methods:

(1) Subscript the list returned by split:

2:26 >perl -Mstrict -wE "my @data = ('A: A_value', 'B: B_value'); for + (@data) { my $a = (split /: /)[1]; say $a; }" A_value B_value 2:30 >

(2) Assign the unwanted value to undef:

2:30 >perl -Mstrict -wE "my @data = ('A: A_value', 'B: B_value'); for + (@data) { my (undef, $a) = split /: /; say $a; }" A_value B_value 2:30 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Store result of split directly to variable(s)
by Perl_Ally (Novice) on Aug 22, 2014 at 16:53 UTC

    Yes, thank you!