Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

regexp: s/// vs s"""

by Anonymous Monk
on Feb 21, 2006 at 14:37 UTC ( [id://531700]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

Maybe I missed it, but it looks like it that something like this
s"(^\\)#.*"$1" ;

is not mentioned in the documentation. So what is the difference between this example and s/(^\\)#.*/$1/ ?
Thanks
perlnoob

Edit: g0n - code tags

Replies are listed 'Best First'.
Re: regexp: s/// vs s"""
by merlyn (Sage) on Feb 21, 2006 at 14:41 UTC
    From perlop:
    If "/" is the delimiter then the initial "m" is optiona +l. With the "m" you can use any pair of non-alphanumeric, non-w +hite- space characters as delimiters. This is particularly u +seful for matching path names that contain "/", to avoid LTS +(leaning toothpick syndrome). If "?" is the delimiter, then the + match- only-once rule of "?PATTERN?" applies. If "'" is the d +elim- iter, no interpolation is performed on the PATTERN. ... If the delimiter chosen is a single quote, no interpola +tion is done on either the PATTERN or the REPLACEMENT. Otherwi +se, if the PATTERN contains a $ that looks like a variable rat +her than an end-of-string test, the variable will be interpolate +d into the pattern at run-time. If you want the pattern compi +led only once the first time the variable is interpolated, use t +he "/o" option. If the pattern evaluates to the empty string, +the last successfully executed regular expression is used instea +d. See perlre for further explanation on these. See perllocal +e for discussion of additional considerations that apply when + "use locale" is in effect.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: regexp: s/// vs s"""
by Corion (Patriarch) on Feb 21, 2006 at 14:40 UTC

    See the discussion of the quote and quote-like operators in perldoc perlop. s/// and s""" are equivalent.

Re: regexp: s/// vs s"""
by inman (Curate) on Feb 21, 2006 at 14:42 UTC
    The first character following the s is used as a delimiter. If the character is normally paired, a matching pair is used.

    s/match/replace/; #The conventional way s|match|replace|; #Useful for urls that contain /s s(match)(replace); #matched braces

    This gives you some flexibility with respect to the code that you are working with. Take care when using characters that are also used in regex notation.

Re: regexp: s/// vs s"""
by CountOrlok (Friar) on Feb 21, 2006 at 14:42 UTC
    from perlop:

    If "/" is the delimiter then the initial m is optional. With the m you can use any pair of non-alphanumeric, non-whitespace characters as delimiters. This is particularly useful for matching path names that contain "/", to avoid LTS (leaning toothpick syndrome). If "?" is the delimiter, then the match-only-once rule of ?PATTERN? applies. If "'" is the delimiter, no interpolation is performed on the PATTERN.

    -imran

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found