Late to the party as usual but here is what I would do.
#!/usr/bin/perl -w use strict; use Data::Dumper; #build some test data here. #create the lists of overlapping values #and unique values my @list_1 = (1 .. 20); my @list_2 = (10 .. 40); #define our sets my (%hash1, %hash2); #we are not interested in the values just #the keys for this exercise so we use a #hash slice, the @hash{@list_of_keys} #construct to build our sample hashes. @hash1{@list_1} = (); @hash2{@list_2} = (); #filter out our stuff. #I like do blocks since they return stuff. my @in1only = do{ #I localize %_ here and set it to %hash1 #you could also use my %temp_hash_for_this_scope #for example but the effect is the same. local %_ = %hash1; #again we see the hash slice thingie this time #we use it with delete which it just so happens #can work with a hash slice. Here we use it to #get rid of keys from %hash2 that might be in #our %hash1. delete @_{keys %hash2}; #finally we return a sorted list of the keys left #over from the delete call above. These are keys #unique to %hash1 only sort keys %_; }; #<---- don't forget the semi-colon for the do block!!!! #same as above... well kinda, just in reverse :) my @in2only = do{ local %_ = %hash2; delete @_{keys %hash1}; sort keys %_; }; print "in one only\n"; print Dumper(\@in1only); print "\n"; print "in two only\n"; print Dumper(\@in2only); print "\n";
and the output...
in one only $VAR1 = [ '1', '2', '3', '4', '5', '6', '7', '8', '9' ]; in two only $VAR1 = [ '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40' ];
-InjunJoel

"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo

In reply to Re: Need advice on hashes and methods by injunjoel
in thread Need advice on hashes and methods by tom2112

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.