Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: strange usage of s///

by davido (Archbishop)
on Sep 03, 2013 at 17:30 UTC ( #1052152=note: print w/ replies, xml ) Need Help??


in reply to Re: strange usage of s///
in thread strange usage of s/// [solved: Perl 5.14 and 5.16 bug]

s/.././gr will convert each consecutive pair of any character (aside from newline) to single dots. If there's an extra (odd) character at the end, this won't be converted, but we don't worry about that because the input seems always to be strings of even numbered length.

Also, don't forget the importance of /r here, as it causes the substitution to return its result without modifying the original string, which is important since we're still working with the original string in the outer layer.


Dave


Comment on Re^2: strange usage of s///
Select or Download Code
Re^3: strange usage of s///
by brx (Pilgrim) on Sep 03, 2013 at 20:35 UTC
    #!perl -pl s/@{[s".."."gr]}\K$"//

    I understand the regex like this:

    s/....\K // (with the good number of '.')

    ...but in facts it works like this:

    s/....\K/ /

    I don't understand why. The usage of $" seems magic too...

    English is not my mother tongue.
    Les tongues de ma mère sont "made in France".

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2014-09-23 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls