>>>     No, you need ++ vs +1.  As they say in perl, ++ is magical and will
>>> do want you want. + 1 will not.
>>>
>>> Wags ;) ps -- is not magical in the same sense as ++ either.
>>
>> How would you decrement a character then? There surely has to be a
>> way?
>
>perldoc -f ord
>perldoc -f chr
>
>   my $len = $#array ;
>   my $x = 0;
>   $array[$x++] = chr( ord($array[$x]) - 1 ) while( $x <= $len );

This decrements ever character in an array.  The ++ is magical in that "a"
increments to "b" and "z" increments to "aa".  (ultimately leading to a cute
little japh)

Your solution takes "abcde" and returns "`abcd" which is not the opposite of
the ++ operator.

The chr(ord($char)-1) part makes sense and applied to "b" gives you "a" and
"z" gives you "y", but "a" gives you "`" and it doesn't make sense for
strings.

To decrement a character you would have to define a boundary condition for
the case of a single "a".

Generally though, you just use substr to strip off the last character and
replace it with it's decrement.  If the last character is "a", then you
strip off the second to last character, replace it with it's decrement and
tack a 'z' onto the end.  If you have a string of all 'a', then you
eventually have to produce a string one character shorter of all 'z'.
Ultimately you have to deal with your boundary condition (undef?).

                                /\/\ark




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to