Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The module suggested by AppleFritter is certainly the easiest way.

But in case you want to do it yourself in pure Perl without using a module, the most idiomatic way to do it is probably to use a hash (or two hashes in this case). This command-line script (re-using AppleFritter sample data) should give you a gist on how to do it:

$ perl -E ' my %hash1 = ("abc" => [1, 2, 3, 4]); my %hash2 = ("abc" => [1, 3, 5, 7]); my %val1 = map {$_, 1} @{$hash1{abc}}; my %val2 = map {$_, 1} @{$hash2{abc}}; say "Values missing in hash2: ", join " ", grep {not exists $val2{$_}} + keys %val1; say "Values missing in hash1: ", join " ", grep {not exists $val1{$_}} + keys %val2; ' Values missing in hash2: 4 2 Values missing in hash1: 7 5
Please ask if there is something you don't understand.

Edit: I had not seen j0se's solution when I suggested mine. Although the two solutions look very different, they are based on exactly the same ideas. I probably would not have posted anything if I had seen j0se's post before. Now it is done, I leave the post, it shows at least that, really, TIMTOWTDI in Perl.

(BTW, j0se, I have spent at least 18 weeks in your country, specifically in Bratislava, working for Orange Slovakia back in 2008 (preparing the Euro transition), and also 6 or 7 more weeks a few years before. And, long before, I also visited Bratislava as a young tourist back in 1975, in a totally different and quite difficult political context. Nice city and very nice people. Sorry for the off-topic digression.)


In reply to Re: Comparing 2 hash tables where values are stored in arrays by Laurent_R
in thread Comparing 2 hash tables where values are stored in arrays by jumpingmonkey

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (9)
As of 2024-04-23 11:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found