Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: rotate a vector with a regex?

by AnomalousMonk (Abbot)
on Nov 20, 2012 at 22:20 UTC ( #1004810=note: print w/ replies, xml ) Need Help??


in reply to rotate a vector with a regex?

... move it pairwise along the string (bubble it).

As I understand it, this won't work because substitution is not being done on the original string during the actual substitution process; rather, an intermediate string is being built up during this process, and the intermediate string is copied to the original string when the process is complete.

That's why something like
    ($x = $y) =~ s{foo}{bar}xms;
works as it does: instead of copying the intermediate back to the original string ($y), it's copied to another string ($x) leaving the original string untouched. (Or maybe $x is just used as the 'intermediate' in the first place. Whatever...)


Comment on Re: rotate a vector with a regex?
Download Code
Replies are listed 'Best First'.
Re^2: rotate a vector with a regex?
by LanX (Canon) on Nov 21, 2012 at 17:29 UTC
    > rather, an intermediate string is being built up during this process, and the intermediate string is copied to the original string

    I think you're right

    DB<123> $x=join "",a..j => "abcdefghij" DB<124> $x =~ s/(.)(?=(.))/$2$1/g => 9 DB<125> $x => "bacbdcedfegfhgihjij"

    Cheers Rolf

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2015-07-30 06:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls