Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: problem with split function

by tcf22 (Priest)
on Oct 20, 2003 at 17:05 UTC ( [id://300664]=note: print w/replies, xml ) Need Help??


in reply to problem with split function

Use quotemeta. This will escape all non-alphanumeric characters. The problem you are running into is the "|" is being interpreted as an "or" in the regex, so you split at "nothing" or "nothing", so it splits the string at every character(equivalent to split(//, $str). Code Sample:
my $str = "1|2|3"; my $delimiter = #get delimiter $delimiter = quotemeta($delimiter); print "$_\n" foreach(split(/$delimiter/, $str)); __OUTPUT__ 1 2 3

- Tom

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-23 07:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found