Tech Support > Computers & Technology > Programming > perl question
perl question
Posted by Kevin on July 30th, 2004


I hope you all consider a perl ? to be okay to post here.
I have a single letter stored in a variable and I want to increment it
to the next letter.

i.e.
$x = "n";
#now i need $x to equal "o";
i tried +1, ++, etc. i searched for increment char and got nothing.
any suggs?

-Kevin

Posted by Peter Ammon on July 30th, 2004


Kevin wrote:

Sure.

$x = chr(1+ord($x)); is one way.

-Peter

--
Pull out a splinter to reply.

Posted by John W. Krahn on July 30th, 2004


Kevin wrote:
$ perl -le' $x = "n"; print $x; $x++; print $x; ++$x; print $x '
n
o
p


John
--
use Perl;
program
fulfillment

Posted by d0x on August 1st, 2004


On Thu, 29 Jul 2004 18:19:19 -0700, Kevin wrote:

#!/usr/bin/perl


@letters = (a .. z);
$x = "n";

for ($i=0;$i<26;$i++) {
if (@letters[$i] eq $x) {
print "$letters[$i+1]";
}
}



Similar Posts