Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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...
--
Brovnik


Comment on Re: Magical Auto-Decrement
Download Code
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.

    —John

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2014-09-01 19:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (17 votes), past polls