in reply to extracting information from arrays
When you need to look up a mapping, like a number mapped to its source, use a hash.
use strict; use warnings; # Just generating data here. my @rep1 = (1..5); my @rep2 = (6..10); my @rep3 = (11..15); my @pairs = map {sprintf "%d %d", int(rand(15)+1), int(rand(15)+1)} 1. +.10; # Here's the magic, fairly information-dense. # Make a list of name-array associations, pass it to map # Then go through the members of the array and associate each member # with the name. my %sources = map { my ($name, $ref) = @$_; map {($_ => $name)} @$ref; } ([rep1 => \@rep1], [rep2 => \@rep2], [rep3 => \@rep3]); # Now, when you have a number $n1, its source is $sources{$n1} my (@locations, @new_gp); for (@pairs) { print "$_: "; my ($n1, $n2) = split; push @new_gp, $n1, $n2; push @locations, @sources{$n1, $n2}; print "$n1 came from $sources{$n1}; $n2 came from $sources{$n2}\n" +; }
|
|---|