in reply to Variable access using other variable data

Instead of using variables with variable names, you should use a hash with the former variable names as keys.

my %fruits = ( pear_apple_peach => 1, pear_damson_orange => 2, ); my @parts = ('pear', 'apple', 'peach'); my $key = join '_', @parts; print $fruits{$key};
Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: Variable access using other variable data
by merrymonk (Hermit) on Oct 17, 2010 at 09:51 UTC
    Thanks for that very quick reply!
    I use multi-dimensional hashes a great deal, therefore your solution means I just have one more
    ‘dimension’ at the beginning and all may well work as I want. Simple!