Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
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

Replies are listed 'Best First'.
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.
Re^3: using split
by girarde (Hermit) 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.
      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
      I think you missed the point entirely:(
      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!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://619235]
help
Chatterbox?
[choroba]: I keep the snippets in files of their own, and use a Makefile to syntax highlight them and insert them into slides, while also running them and inserting the output if required
[Corion]: choroba: Ooooh - I didn't think of that! I write my presentations as POD and if it "roughly" looks like Perl code, I should also syntax-check that...
[haukex]: Yes sorry I don't run them all the time, my POD tests are only run as author tests (and are excluded when I'm using Devel::Cover)
[Corion]: choroba: Hmm - no, I keep the snippets inline, but as my framework also has support for capturing output etc., maybe I should do the same...
[Corion]: haukex: Yes, that approach is sane, and it heals the fragility of Pod parsers in a nice way while still syntax-checking stuff
[choroba]: Unfortunately, none of it is online
[haukex]: I figured that POD tests make sense, but only as author tests
[choroba]: I mean, the slides are, but not the makefile with scripts to create them
[Corion]: haukex: I've only now arrived at that revelation ;)
[Corion]: choroba: I use spod5, which also has that support, and also implements its own kinda-make stuff

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2017-02-27 12:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (385 votes). Check out past polls.