In Perl, how do I make hash from arrays @A and @B having equal number of elements? The goal is to have each value of @A as key to value in @B. The resulting hash %C would,then make it possible to uniquely identify an element from @B supplying key from @A.
it's as simple as
my %c;
@c{@a} = @b;
use List::MoreUtils 'mesh';
my %c = mesh @a, @b;
That's how it's made internally (if you're sure about equal number of elements):
my %c = map { $a[$_] => $b[$_] } 0 .. $#a;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With