http://www.perlmonks.org?node_id=1009441


in reply to Get same position value in 2nd array

What frozenwithjoy said, but here's a first pass at something like what "... use hashes, but the look-up values themselves are actually variables made up of a scalar and a string of text appended to them ..." might look like:

>perl -wMstrict -le "my $foo = 'Bar'; ;; my %hash = ( 'BarBaz' => 'Quux' ); ;; print $hash{ $foo . 'Baz' }; " Quux

Update: Likewise for the OP second paragraph (but a hash might be better here):

>perl -wMstrict -le "my @ra1 = ( 0, 1, 2, 0, 3, -1); my @ra2 = qw(eeew ok fine yech great bad); ;; RA1: for my $i (0 .. $#ra1) { next RA1 unless $ra1[$i] > 0; do_something_with($ra1[$i], $ra2[$i]); } ;; sub do_something_with { print qq{$_[0]: '$_[1]'}; } " 1: 'ok' 2: 'fine' 3: 'great'