#! perl use strict; use warnings; use Data::Dumper; my %categories = ("FUR-BO 10001798" => 'Furniture', "FUR-CH 10000454" => [ 'Furniture' , 'Chairs'], "OFF-LA 10000240" => [ 'Office Supplies' , 'Labels', 'Office SuppliesA' , 'Labels', 'Office SuppliesB' , 'Labels', 'Office SuppliesC' , 'Labels', 'Office SuppliesD' , 'Labels', ], "OFF-ST 10000107" => [ 'Office Supplies' , 'Storage' +], "OFF-AR 10003056" => [ 'Office Supplies' , 'Art'], "TEC-PH 10001949" => 'Technology Phones', ); my @items = ('Furniture', 'Furniture,Chairs', 'Technology Phones', 'Office Supplies,Storage', 'Office Supplies,Art', 'Office Supplies,Labels', map {"Office Supplies$_,Labels"} 'A'..'D' ); Search(split /,/,$_) for @items; exit 0; sub Search{ my (@search_words) = @_; print "Searching for @search_words ...\n"; my @category = (); foreach my $categorycode (keys(%categories)) { if(ref(my $carray = $categories{$categorycode}) eq 'ARRAY' ){ + for (my $idx=0; $idx < $#$carray; $idx +=2){ my @current = @$carray[$idx,$idx+1]; if ( $#current == $#search_words and join ("", @current) eq join ("",@search_words +)){ push @category, $categorycode; } } next; } if(my $reftype = ref($categories{$categorycode})){ die "ERROR: Unxpected type: $reftype for item $categoryco +de"; } if( $categories{$categorycode} eq $search_words[0] and @sear +ch_words ==1) { push(@category, $categorycode); } } print join(", ", @category) . "\n"; }

                Memory fault   --   brain fried


In reply to Re^3: return Hash key while hash value/values is search criteria by NetWallah
in thread return Hash key while hash value/values is search criteria by Magnolia25

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.