Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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
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 contemplating the Monastery: (14)
As of 2014-12-26 06:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (166 votes), past polls