in reply to Search multiple variables

G'day Raya4505,

Welcome to the monastery.

Firstly, I'm unsure on a couple of things so I've assumed: @array and @Encephalitis_77 are two different sources that you want to search; and, @found contains related information beyond the "Primary Diagnosis". You'll probably need to make changes to the example code below; however, the basic technique should be valid.

If you organise your data into a hash with a structure like this:

code1 => { source1 => { primary => 'diagnosis', other => 'information', }, source2 ... }, code2 ...

You can write a short subroutine to quickly search for the information you want. The basic technique (with a couple of example searches) are shown in this script:

#!/usr/bin/env perl -l use strict; use warnings; my %data_for = ( 6280 => { array => { primary => 'Meningitis', other => 'Other relevant info ...', }, Encephalitis_77 => { primary => 'Encephalitis', other => 'Other relevant info ...', }, }, ); search_for_diagnosis_code($_) for (6280, 9999); sub search_for_diagnosis_code { my ($search) = @_; print "Searching for '$search' ..."; if (exists $data_for{$search}) { for my $source (keys %{$data_for{$search}}) { print "\tFound in '$source':"; print "\t\tPrimary Diagnosis: $data_for{$search}{$source}{ +primary}"; print "\t\tOther Information: $data_for{$search}{$source}{ +other}"; } } else { print "\tNo data found."; } }

Output:

Searching for '6280' ... Found in 'array': Primary Diagnosis: Meningitis Other Information: Other relevant info ... Found in 'Encephalitis_77': Primary Diagnosis: Encephalitis Other Information: Other relevant info ... Searching for '9999' ... No data found.

-- Ken