in reply to Render numeric sequence as array of letters

Without testing (no Perl on this machine...), I am willing to bet that your code does not work. 100 is going to sort first because sort is lexigraphical. But here is an alternate solution that should work fine even for long sequences.
my @original_array = qw(5, 100, 2, 8, 40); # Build lookup hash my %num2letter; my $char = "A"; foreach my $num (sort {$a <=> $b} @original_array) { $num2letter{$num} = $char++; } my @letter_sequence = @num2letter{@original_array};
(Note - if you are looping over an array searching for something, then you probably wanted a hash...)

Update: Change map to a more efficient slice as suggested by Aristotle, remove accidental space within a my.

Replies are listed 'Best First'.
Re^2: Render numeric sequence as array of letters (useless use of map())
by Aristotle (Chancellor) on May 21, 2003 at 12:25 UTC
    Any reason not to use a slice here?
    my @letter_sequence = @num2letter{@original_array};

    Makeshifts last the longest.

      You are exactly right, there is no reason not to use the more efficient slice operation. I just wasn't thinking that way.