Hi Monks!
I am trying to match a value I get from an XML file and compare this value and find a match with values in a hash. I have this sample code and I hope it will explain what I am trying to do.
#!/usr/bin/perl -w use strict; my @code_reference = qw(aaaa qqqqq 7781q 09888 wetrt); foreach my $code(@code_reference) { my $place = "http://mylocation?param=" . $code ; my $data = XML::TreePP->new(); my $all_data = $data->parsehttp( GET => $place ); # This will return a different value for each "@code_reference". It co +uld be like: # "Value: AE" "Value: YY" "Value: C" "Value: P" "Value: PP" from my XM +L my $got_data=$all_data->{xml}->{code}->{"-data"}; # I have this hash, that I am trying to match lets say, if I got "Valu +e: AE", I want to # find the value in the hash the match "AE" and print. my %wind_dir = ( 'Loc A' => 'AA,A,AE,AB,BB,EA,C', 'Loc B' => 'TT,T,AE,B', 'Loc C' =>'PP,P,PA', 'Loc D' =>'YY, TT,P,OP,QA' ); # It should print: Loc A found AE # Loc B found AE
How can I do that, I hope I am been clear with this sample code to illustrate what I am trying to do.
Thanks for the help!

In reply to Matching value in hash help! by Anonymous Monk

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.