Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Re: string increment

by gargle (Chaplain)
on Sep 13, 2005 at 11:48 UTC ( [id://491555]=note: print w/replies, xml ) Need Help??


in reply to Re: string increment
in thread string increment

How about some base 26 arithmetic!

perl -e '$s="aaa";for $i (1..28) { ++$s }; print $s;'

gives me 'abc' as its output for 28 increments. So lets consider 'abc' as a 'number':

perl -e 'use Math::BaseCalc;$c = new Math::BaseCalc(digits => [a..z] );print $c->from_base("abc");

The code above gives me back my 28 increments. Ain't perl fun?

To integrate it in your code can be more difficult however because your base string doesn't have to be 'aaaaaaa'. But a little math can do the trick.

--
if ( 1 ) { $postman->ring() for (1..2); }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-26 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found