Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Store result of split directly to variable(s)

by Athanasius (Archbishop)
on Aug 22, 2014 at 16:32 UTC ( [id://1098342]=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-20 16:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found