Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Get same position value in 2nd array

by AnomalousMonk (Chancellor)
on Dec 18, 2012 at 18:08 UTC ( #1009441=note: print w/replies, xml ) Need Help??

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'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1009441]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2018-06-18 10:26 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (109 votes). Check out past polls.