Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Magical Auto-Decrement

by Brovnik (Hermit)
on Jul 04, 2001 at 21:34 UTC ( [id://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

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.

    —John

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-18 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found