Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: rotate a vector with a regex?

by frozenwithjoy (Curate)
on Nov 20, 2012 at 22:00 UTC ( #1004807=note: print w/ replies, xml ) Need Help??


in reply to rotate a vector with a regex?

Are you interested in the end product or do you want all intermediates?

This will give you the end product:

#!/usr/bin/env perl use strict; use warnings; use feature 'say'; my $string = "12345"; $string = substr( $string, 1 ) . substr( $string, 0, 1 ); say $string; __END__ 23451

EDIT: Just realized you were asking for something else. Oops. I think AnomalousMonk is correct about it not being possible this way. Regarding the errors, you need to specify the second capture group since the second set of parentheses you have are part of the lookahead. This gets rid of the warnings:

$ perl -WE '$string = "12345"; $string =~ s/(.)(?=(.))/$2$1/g; say $st +ring' 213243545


Comment on Re: rotate a vector with a regex?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2014-07-31 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (242 votes), past polls