Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Get same position value in 2nd array

by AnomalousMonk (Abbot)
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'


Comment on Re: Get same position value in 2nd array
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1009441]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2014-12-26 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls