Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: split line

by linuxer (Curate)
on Jul 28, 2008 at 21:18 UTC ( #700658=note: print w/replies, xml ) Need Help??


in reply to split line

you should read the perldoc of split. It can do some magic..., especially when you use $_ as expression; you don't need to bother with leading whitespaces (which might be unwanted in the resulting list)

my $line = " 0 10 9 4 1 0 0 0 2 2 1 1 0"; my @config = (); { # dedicated block because localizing some variables ($_) local $_ = $line; @config = split; } # some code using @config { # dedicated block because localizing some variables ($, and $\) # show result; local $, = local $\ = $/; print @config; }

update: code comments added

update2: see moritz' answer for the better solution whithout localizing $_

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2022-11-29 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?