Perl Monk, Perl Meditation | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Say I'd like to move the first char in a string to the other end. An obvious choice might be
s/(.)(.+)/$2$1/ But I wondered- what if I tried to move it pairwise along the string (bubble it). It seems like as long as I could get the matching position to move by 1, instead of 2, I could do it that way. Just for academic reasons I wondered.. It seems like something along these lines, with the positive lookhead, could potentially bubble the char: s/(.)(?=.)/$2$1/g; which I'd hoped would perform these steps: 12345 21345 23145 23415 23451 but instead it produced 5 warnings and left the string unchanged (I presume the warnings were that $2 was undef).. Thoughts, wondrous monks? In reply to rotate a vector with a regex? by misterperl
|
|