in reply to Convert a number to another number?

Use a hash:
use strict; use warnings; my %lookup = ( 1 => 567898, 2 => 543267, ); my @test = qw(0 a 2 1); for (@test) { print exists $lookup{$_} ? $lookup{$_} : $_, "\n"; } __END__ 0 a 543267 567898

Replies are listed 'Best First'.
Re^2: Convert a number to another number?
by Narveson (Chaplain) on Sep 16, 2008 at 18:40 UTC

    In the TMTOWTDI spirit, if your keys are really going to be "1", "2", "3", "4", and so on, you can use an array:

    my @lookup; @lookup[1..4] = ( 567898, 543267, 234565, 987654, ); my @test = qw(0 a 2 1); for (@test) { print defined $lookup[$_] ? $lookup[$_] : $_, "\n"; }
A reply falls below the community's threshold of quality. You may see it by logging in.