Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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 romping around the Monastery: (6)
As of 2015-07-28 06:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls