Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: string increment

by davido (Cardinal)
on Sep 13, 2005 at 07:34 UTC ( [id://491505]=note: print w/replies, xml ) Need Help??


in reply to Re: string increment
in thread string increment

The behavior is not unusual. If you incremented 1111 you would get 1112, and if you incremented it ten times you would get 1121. Eleven times would give you 1122. A hundred times would give you 1211... you get the idea.

So, given that alpha characters can also be incremented, it should come as no surprise that they're incremented right to left also; consider the right-most digit to be the least significant digit, whether it's a number or an alpha character. Thus, 'aaaa' would become 'aaab'. Increment it enough times, it it becomes 'aaba', 'aabb', 'aabc' ... 'aaca', 'aacb', 'aacc', and so on, until you finally arrive at 'zzzz'.

If you really just wanted to increment each character by one, you might consider constructing a regexp like this:

$string =~ s/(.)/$char = $1;++$char/eg;

Dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-29 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found