How to extract partial information from Dumper data with a key?
$VAR1 = {
'fruit' => 'apple',
'uniqueID' => 'red'
};
$VAR2 = {
'fruit' => 'apple',
'uniqueID' => 'green',
};
Expected output
key = green
my @found;
If key is in data (search for uniqueID),
found = $VAR2 = {
'fruit' => 'apple',
'uniqueID' => 'green',
};
It looks like you have a list of data structures, that you are passing to Data::Dumper.
That would produce the output with
$VAR1and$VAR2you've shows in the question.Now if you want to search for the data structure inside
@all_resultswhere the keyuniqueIDis"green", you can usegrepto look into every data structure, and filter out only the one you want.Note that you need the parentheses
()around the new variable, asgrepreturns a list. You need to assign in list context, otherwise you'll get the number of elements of the result back. (That's1in this case).The output of above code is