in reply to Render numeric sequence as array of letters

Assuming A-Z will suffice:
my @original_array = qw(5 100 2 8 40); my @letter_seq = do { my %letter_for; @letter_for{sort { $a <=> $b } @original_array} = ('A' .. 'Z'); @letter_for{@original_array}; };

Makeshifts last the longest.

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

    I believe this code has similar problems to my initial posting, which merlyn was quick to point out. If the @original_array contains one duplicate, for example, then the same grade is assigned for both, but one letter will be skipped in the process.

    Just a heads up.

      True.
      my @original_array = qw(5 100 2 8 8 40); my @letter_seq = do { my %letter_for; @letter_for{@original_array} = (); @letter_for{sort { $a <=> $b } keys %letter_for} = ('A' .. 'Z'); @letter_for{@original_array}; };

      Makeshifts last the longest.