in reply to concatenate scalar with array name

Instead of attempting to create variables 'on the fly,' consider creating a hash of arrays (HoA) whose keys are array1 .. array5:

use strict; use warnings; my %hash; for my $i ( 1 .. 5 ) { for my $k ( 0 .. 4 ) { ${ $hash{ 'array' . $i } }[$k] = $i**$k; } } print "$_: @{ $hash{ $_ } }\n" for sort keys %hash;

Output:

array1: 1 1 1 1 1 array2: 1 2 4 8 16 array3: 1 3 9 27 81 array4: 1 4 16 64 256 array5: 1 5 25 125 625

Hope this helps!

Replies are listed 'Best First'.
Re^2: concatenate scalar with array name
by boftx (Deacon) on Jan 15, 2014 at 06:24 UTC

    Not a bad approach. I was thinking only in terms of what he asked, but that would accomplish the same thing. :)

    It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.