Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Magical Auto-Decrement

by Brovnik (Hermit)
on Jul 04, 2001 at 21:34 UTC ( #93899=note: print w/replies, xml ) Need Help??

in reply to Magical Auto-Decrement

Nice try, but of course, the issue re. the boundary cases still holds, so the following
--"a" gives "z" --"a00" gives "z99" --"0" gives "9" --"aa00" gives "zz99"
give results which aren't reversible. Update: (following comment below)

Yes, you should eat the left-char on underflow, and --"a" => undef and --0 => undef.

I was going to make a point about keeping items in the right order for a sort, but of course zz++ == aaa which screws up that point. Hmmm...

Replies are listed 'Best First'.
Re: Re: Magical Auto-Decrement
by John M. Dlugosz (Monsignor) on Jul 04, 2001 at 21:40 UTC
    Looks like increment will add another character upon overflow, presumably duplicating the kind of the previous leftmost. To undo ++, the -- could eat the leftmost upon underflow. But ++ can't always be the exact opposite since it doesn't know which kind of character to add.

    I'm aware that I'm clamping on underflow. It's a snippet, not a polished module! It was done more for the challange, but if I really needed this (like the poster that inspired it), I'd have the function croak or something, if this was significant to the program.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://93899]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2018-04-26 21:55 GMT
Find Nodes?
    Voting Booth?