Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Split ( ) is Giving Me a Splitting Headache

by bpphillips (Friar)
on May 24, 2006 at 12:32 UTC ( #551342=note: print w/ replies, xml ) Need Help??


in reply to Split ( ) is Giving Me a Splitting Headache

From the manual you evidentally didn't find (perldoc) :-)

perldoc -f split split /PATTERN/,EXPR,LIMIT split /PATTERN/,EXPR split /PATTERN/
In your case, you're only passing in a single argument to split. Perl interprets this as /PATTERN/ and implicitly uses $_ as the EXPR. Since $_ hasn't been initialzed yet (hence the warning) nothing really happens (it's trying to split an undefined value on occurences of "Hello World").

What you need to do (besides taking a look at the perldoc entry for split) is use the two-argument usage of split:
my $Phrase = "Hello World"; my @Parts = split(/ /, $Phrase); # split $Phrase on spaces


-- Brian


Comment on Re: Split ( ) is Giving Me a Splitting Headache
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2015-07-06 21:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls