in reply to Render numeric sequence as array of letters
(Note - if you are looping over an array searching for something, then you probably wanted a hash...)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};
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 | |
by tilly (Archbishop) on May 21, 2003 at 18:19 UTC |