Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Surprised by split

by gellyfish (Monsignor)
on Aug 11, 2005 at 10:03 UTC ( [id://482887]=note: print w/replies, xml ) Need Help??


in reply to Surprised by split

You are getting stuffed up by the quoting here. You should bear in mind in the first instance that the first argument to split is a regular expression, and it is often prefered use the // rather than quotes. In your first attempt you are asking to split on anything or anything ('|' being the regex alternation character), in your second you are basically getting the same thing because the '\' is being eaten in the double quoted context (i.e. escaping the '|') and the third is correct because you are now escaping the '\' so you get a literal '\|'. You probably want to either use single quotes or the // for clarity.

use warnings; use strict; + my $str = "lhs|rhs"; + print "\n" . join " ", split '\|', $str; print "\n" . join " ", split /\|/, $str;

/J\

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-03-28 11:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found