Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Whats with the autoincrementation of a string

by LanX (Saint)
on Jun 14, 2013 at 18:56 UTC ( [id://1039018]=note: print w/replies, xml ) Need Help??


in reply to Whats with the autoincrementation of a string

Think of every position as a wheel in a mechanical counter.

There are three kinds of wheels 0-9, a-z and A-Z which can be independently be chosen for each position.

Clearer now? =)

edit
perlop
the increment is done as a string, preserving each character within its range, with carry: print ++($foo = '99'); # prints '100' print ++($foo = 'a0'); # prints 'a1' print ++($foo = 'Az'); # prints 'Ba' print ++($foo = 'zz'); # prints 'aaa'

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^2: Whats with the autoincrementation of a string
by space_monk (Chaplain) on Jun 14, 2013 at 20:09 UTC

    Not quite independently. Any numeric wheels must be at the back.

    e.g. 'Aa00' will work, '00Aa' won't.

    If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)
      Sure, anything with leading digits which isn't a proper number is dealt by atoi in numeric context, IIRC that's due to some C legacy.

      DB<109> @a=a..c => ("a", "b", "c") DB<110> $a[" 1x"] => "b"

      plz note: only with no warnings!

      Cheers Rolf

      ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-25 20:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found