in reply to normal array exists question
my %out_hash = (); @out_hash{@in_array, keys %in_hash} = (("0") x @in_array, values %in_h +ash);
BTW, a "normal array" is always just called an array. A "hash array" is usually called just a hash, but sometimes is called an associative array.
The aboove works using a "hash slice". This looks like @hash{LIST}, and results in a list (which can be assigned to) of the values in %hash for each key in LIST. It also uses the x operator to make a list of scalar(@in_array) "0"'s.
So the assignment will initially set $out_hash{key} to "0", for each key in @in_array, then set $out_hash{key} to $in_hash{key} for each key in %in_hash.
Update: the above is not likely to be useful to you. I misinterpreted your "match" to mean "eq", instead of a regex match. It would be helpful if you would annotate the sample code to show which parts do and which parts don't work as you expect. Would I be correct in guessing it is just the final if statement that doesn't do what you want? I suspect you meant !~, not != there, but even that won't do what you want. You have to loop over all the keys seeing if they do match.
Update: removed extra )
|
---|