Phoenix.pm: Incrementing Characters in Perl

Frooninckx Craig - cfroon Craig.Frooninckx at acxiom.com
Tue Sep 16 16:14:01 CDT 2003


I've got a function I'm converting from C to Perl.  One of the things I do
is add to letters, so for instance my C code is
char letter;

letter = 'A';
letter += 3;

which would make letter 'D'.  

In Perl this doesn't work
$letter = 'A';
print $letter , "\n";
$letter = $letter + 4;
print $letter , "\n";

prints 'A' , '4'

Using chr and Ord I found a way to make it work.  

$letter = 'A';
print $letter , "\n";
$letter = chr(ord($letter) + 4);
print $letter , "\n";

But I was wondering if you could think of anything slicker, using regex, tr,
or something like that.  No big deal as I do have a solution.  Just
wondering if there is a better way to do it.

-Craig





**********************************************************************
The information contained in this communication is
confidential, is intended only for the use of the recipient
named above, and may be legally privileged.
If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination, 
distribution, or copying of this communication is strictly
prohibited.
If you have received this communication in error,
please re-send this communication to the sender and
delete the original message or any copy of it from your
computer system. Thank You.




More information about the Phoenix-pm mailing list