Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Render numeric sequence as array of letters

by perlguy (Deacon)
on May 19, 2003 at 21:18 UTC ( [id://259295]=note: print w/replies, xml ) Need Help??


in reply to Render numeric sequence as array of letters

How about:

my $count = 65; # 65 is the letter 'A' in ASCII my @original_array = qw(5 100 2 8 40); my %original_map = map { $_ => chr($count++) } sort { $a <=> $b } @original_array; my @letter_sequence = map $original_map{$_}, @original_array; print "@letter_sequence\n";

Update: Good call, merlyn. Here is one to eliminate the duplicates, I think:

my %seen; my %original_map = map { $_ => chr($count++) } grep !$seen{$_}++, sort { $a <=> $b } @original_array;

Replies are listed 'Best First'.
•Re: Re: Render numeric sequence as array of letters
by merlyn (Sage) on May 19, 2003 at 21:22 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-19 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found