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
$VAR1
and$VAR2
you've shows in the question.Now if you want to search for the data structure inside
@all_results
where the keyuniqueID
is"green"
, you can usegrep
to look into every data structure, and filter out only the one you want.Note that you need the parentheses
()
around the new variable, asgrep
returns a list. You need to assign in list context, otherwise you'll get the number of elements of the result back. (That's1
in this case).The output of above code is