Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: split and join

by Anonymous Monk
on Apr 22, 2002 at 22:38 UTC ( #161169=note: print w/ replies, xml ) Need Help??


in reply to split and join

what if you need to split by the plus character "+" the compiler keeps on chucking a spazz. is there anyway to get around this?? simon.hilton@sun.com


Comment on Re: split and join
Replies are listed 'Best First'.
Re: Re: split and join
by Albannach (Prior) on Apr 22, 2002 at 23:42 UTC
    split takes a pattern (more or less a regular expression, though there are special cases you might want to read up on), not a static string to separate chunks in the input string, and it happens that the '+' character is special, so you just need to escape it like so:
    @array = split '\+', 'abc+def'; print "@array";
    gives abc def
    By the way, you might want to provide the actual error message in future if you need assistance, as "chucking a spazz" covers a lot of bases!

    --
    I'd like to be able to assign to an luser

Re: Re: split and join
by Zaxo (Archbishop) on Apr 22, 2002 at 23:35 UTC

    '+' is a metacharacter which has meaning in regular expressions. To match a literal plus, you need to escape ('backwhack') it.

    split /\+/;

    After Compline,
    Zaxo

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2015-07-30 21:31 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 (273 votes), past polls