Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: using split

by imp (Priest)
on Jun 04, 2007 at 21:30 UTC ( #619235=note: print w/ replies, xml ) Need Help??


in reply to Re: using split
in thread using split

There is no difference in the two lines you listed.

perl -MO=Deparse -e "split('|', 'ab|c');" split(/|/, 'ab|c', 0); -e syntax OK


Comment on Re^2: using split
Download Code
Re^3: using split
by girarde (Friar) on Jun 04, 2007 at 21:53 UTC
    I think the difference is that when | is quoted it gets treated as a literal instead of a regex 'or', i.e., it will split the string on the pipe characters.
      I think you missed the point entirely:(
      One of the most valuable things I learned from perlmonks is to always test my assumptions. Before posting a response to a question I always run the example code that I am providing and verify that it works the way I anticipate.

      The reply I provided above demonstrates that the perl parser sees the two statements as equivalent. Here is an example that proves the behaviour:

      > perl -le "print for @cols = split('|', 'ab|c');" a b | c
      What would you have in mind if you knew from split that the first argument is /PATTERN/? :-)

      Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Re^3: using split
by BrowserUk (Pope) on Jun 05, 2007 at 02:30 UTC

    There is one subtle difference between using '...' and /.../ as regex delimiters. The latter interpolates where the former does not. That does not affect the examples in this thread though.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      And the difference between "..." and /.../ is that "..." unescapes too much.

      For example,
      "\d" is the same as /d/.
      If you want /\d/, the equivalent would be "\\d".

      I always use /.../ or qr/.../ to avoid confusion.

        Yes. I never use "...", preferring m[...] instead. Using '...' for a regex is simply shorthand for m'...' which gives the same, non-interpolating behaviour.

        A bad habit? Maybe...


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-08-21 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (128 votes), past polls