Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: rotate a vector with a regex?

by frozenwithjoy (Priest)
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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2016-10-21 00:43 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (284 votes). Check out past polls.