in reply to Re: Search multiple variables
in thread Search multiple variables

Ok, thank you so much for responding!!Your code works wonderfully. The only other thing is that I need to search multiple items (so instead of $Search, perahaps @Search or it could read from a formatted CSV file) and then I need perl to pick the one that shows up the most as the primary, but still display the other ones. If the results could display something like:

Primary diagnosis (code that showed up the most for the particular per +son): Cancer of the throat (7) Other diagnosis: Benign Neoplasm (3 - as in it showed up three times) +Leukemias (2)

I probably didn't make that very clear sorry, and I may be getting greedy here, but any help would be so appreciated!

Do you have any ideas for that? THANK YOU

Replies are listed 'Best First'.
Re^3: Search multiple variables
by hdb (Monsignor) on Feb 21, 2014 at 07:15 UTC

    Put another loop around the loop over the diagnoses:

    my @Search = qw( 6280 3141 2718 1414 ); my %frequency; for my $Search (@Search) { for my $diag ( keys %diags ) { if( my @found = grep { $_ eq $Search } @{$diags{$diag}} ) { my $found = join ",", @found; print "Primary diagnosis: $diag, $found\n"; $frequency{$Search}++; } } }

    and then do something based on the %frequency of found diagnoses.

      Did anyone every tell you that you are a genius? Because you definitely are. Thank you so much for helping me. thank you for everyone else who responded. I have used some of the other comments in other scripts of mine.

        Thanks for your praise but this is rather basic Perl. If you think it useful, hang on to it, learn and practise. You can be there in no time as well.