|No such thing as a small change|
Re: extracting only those keys with uniq values in array listby davido (Cardinal)
|on Apr 20, 2021 at 15:50 UTC||Need Help??|
In your question you should post an example of the data structure you are working with. Your description says that you are dealing with a hash of arrays, and that for every key there are two values. In some cases those two values are the same, and in other cases they are not. Since you're using substr in your example, I'll assume that "the same" means stringwise equality.
I'm imagining that your datastructure looks like this:
In this structure you would want to print the name of the bar key and buzz key, since the values in the array ref for those keys are the same. You didn't suggest that there could ever be more or less than two values, so I won't solve the problem that isn't stated. Here's an example of how to accomplish what you're after given this data structure:
The output now should be 'bar' and 'buzz'.
If there could be fewer than two elements to compare, you could do this:
If there could be more than two, and you want to assure that they are all equal, you could do this:
If these scenarios don't match the problem you are trying to solve, please refine your question to remove the ambiguity that has resulted in a diverse selection of answers.