Oh, ok, that's great. :)

Actually, hashes don't necessarily need to have values assigned to the elements. But in your case, it doesn't matter; either assign a value or don't. Here's an example:

my %hash; while ( <DATA> ) { chomp; $hash{$_} = 1; }

Or even:

my %hash = map { chomp; $_ => undef } <DATA>;

If you need to massage each line so that you have only the mac address, that is pretty easy to do too. The second example does slurp the file, so beware if your files are massive. Of course you'll have to have at least enough resources to hold all the mac addresses in memory anyway.

After reading that first file, and creating your hash, you can go through and use the hash values as flags to mark on each subsequent file if the mac address is found. At the end of each file read, check to see if you've flagged all hash keys, and each hash element that doesn't have its flag turned on, you can delete. Then reset all flags (or use a different flag for the next file), and so on.

It's just one way.


Dave


In reply to Re^7: Comparing files by davido
in thread Comparing files by dannyp

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.