######################## use strict; use warnings; use Data::Dumper; ######################## my $filename = "physical_disks.txt"; my $aoh_ref_physical_disks; open my $fh, "<", $filename or die "Cannot open file $filename: $!"; while (<$fh>) { #Do stuff here so that the following Array of Hashes is generated. #Try later to put all the seperate next ifs into a single statement. next if $_=~ /^Storage/; next if $_=~ /^HTTPS/; next if $_=~ /^$/; my ($filekey, $filevalue) = (split /\s+=\s+/, $_); #print "$filekey => $filevalue\n"; push @$aoh_ref_physical_disks, {$filekey => $filevalue}; } foreach my $disk (1..$#$aoh_ref_physical_disks) { foreach my $key (sort keys $aoh_ref_physical_disks->[$disk]->%*) { #Add if loop here that checks if the key "Health status" #is anything but ok or if the key "Health details" does not #contain the word "normal", then print out the other details #such as #$aoh_ref_physical_disks->[$disk]->{'ID'} #$aoh_ref_physical_disks->[$disk]->{'Health status'} #$aoh_ref_physical_disks->[$disk]->{'Health details'} #$aoh_ref_physical_disks->[$disk]->{'Model'} } } #Use Data::Dumper output to verify. print Dumper($aoh_ref_physical_disks);