Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

wwwxxxAPC, How to unsubscrube from dategen spam, WWWXXXAPC, docmd.close 2585, WWWXXXDOCO, nu vot, dhcpd lease file "binding state", WWWXXXDOCO, how to setup procmail to process html2text, how to setup procmail html2text

Links

XODOX
Impressum

#1: num to alpha

Posted on 2006-02-27 07:28:05 by The Ghost

What's the easiest way for me to turn a number into a letter?

2 -> b
5 -> e
26 -> z
27 -> error

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Report this message

#2: Re: num to alpha

Posted on 2006-02-27 07:52:46 by krahnj

The Ghost wrote:
> What's the easiest way for me to turn a number into a letter?
>
> 2 -> b
> 5 -> e
> 26 -> z
> 27 -> error

my @convert = ( undef, 'a' .. 'z' );

if ( $number > 0 && defined $convert[ $number ] ) {
print "$number = $convert[$number]\n";
}
else {
print "Error: $number is not a valid number.\n";
}


Or:

my %convert = qw[ 1 a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9 i 10 j 11 k 12 l 13 m 14 n
15 o 16 p 17 q 18 r 19 s 20 t 21 u 22 v 23 w 24 x 25 y 26 z ];

if ( exists $convert{ $number } ) {
print "$number = $convert{$number}\n";
}
else {
print "Error: $number is not a valid number.\n";
}


Or:

if ( $number >= 1 && $number <= 26 ) {
print "$number = ", chr( $number + ord( 'a' ) - 1 ), "\n";
}
else {
print "Error: $number is not a valid number.\n";
}



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Report this message

#3: RE: num to alpha

Posted on 2006-02-28 00:18:40 by Timothy Johnson

Just for the sake of one more way to do it:

###########################

use strict;
use warnings;

my %numbers;
my $letter =3D 'a';
my $userinput =3D 23;

foreach(1..26){
$numbers{$_} =3D $letter;
$letter++;
}

if(defined($numbers{$userinput})){
print "It's good!\n";
}else{
print "Invalid number.\n";
}

############################



-----Original Message-----
From: The Ghost [mailto:ghost@madisonip.com]=20
Sent: Sunday, February 26, 2006 10:28 PM
To: Perl Beginners
Subject: num to alpha

What's the easiest way for me to turn a number into a letter?

2 -> b
5 -> e
26 -> z
27 -> error

--=20
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>




--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Report this message

#4: RE: num to alpha

Posted on 2006-02-28 04:08:44 by gjkeenan

>
>my %convert = qw[ 1 a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9 i 10 j 11 k 12 l 13 m
14 >n
>15 o 16 p 17 q 18 r 19 s 20 t 21 u 22 v 23 w 24 x 25 y 26 z ];
>

Hi,

I know John Krahn is a fan of %map. He has advised me on using it before.

Just wondering if there was any reason he chose to use %convert instead in
his example above.

Cheers,
Greg.

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Report this message

#5: Re: num to alpha

Posted on 2006-02-28 04:50:24 by krahnj

Timothy Johnson wrote:
> Just for the sake of one more way to do it:
>
> ###########################
>
> use strict;
> use warnings;
>
> my %numbers;
> my $letter = 'a';
> my $userinput = 23;
>
> foreach(1..26){
> $numbers{$_} = $letter;
> $letter++;
> }

Or:

my %numbers;

@numbers{ 1 .. 26 } = 'a' .. 'z';


John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Report this message

#6: Re: num to alpha

Posted on 2006-02-28 05:10:17 by krahnj

Keenan, Greg John (Greg)** CTR ** wrote:
>>my %convert = qw[ 1 a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9 i 10 j 11 k 12 l 13 m
> 14 >n
>>15 o 16 p 17 q 18 r 19 s 20 t 21 u 22 v 23 w 24 x 25 y 26 z ];
>>
>
> Hi,

Hello,

> I know John Krahn is a fan of %map.

I am?

> He has advised me on using it before.
>
> Just wondering if there was any reason he chose to use %convert instead in
> his example above.

%map and %convert are just hash names, you can use any name that you want.


John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Report this message

#7: RE: num to alpha

Posted on 2006-02-28 05:21:35 by gjkeenan

>> I know John Krahn is a fan of %map.

>I am?

>> He has advised me on using it before.
>>
>> Just wondering if there was any reason he chose to use %convert
>> instead in his example above.

>%map and %convert are just hash names, you can use any name that you want.


Sorry - my mistake.

Still trying to get the hang of perl and I've totally confused a few things.
Back to the books for me!

Cheers,
Greg.

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Report this message

#8: Re: num to alpha

Posted on 2006-02-28 05:55:46 by krahnj

Keenan, Greg John (Greg)** CTR ** wrote:
>>>I know John Krahn is a fan of %map.
>
>>I am?
>
>>>He has advised me on using it before.
>>>
>>>Just wondering if there was any reason he chose to use %convert
>>>instead in his example above.
>
>>%map and %convert are just hash names, you can use any name that you want.
>
>
> Sorry - my mistake.
>
> Still trying to get the hang of perl and I've totally confused a few things.
> Back to the books for me!

Don't worry about it, understanding Perl can be confusing. :-)


John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Report this message