in reply to Comparing files

One way to do it would be to read each file, pulling out the mac addresses, and then use the mac addresses as hash keys. Something like "$found{$addr}++". Once you've done that, having read each file, %found will contain a list of all mac addresses, and a count for each address. If count == 30, you know that particular address was found in all 30 files, and you can output that key to your new file.

Hope that helps...

If none of this makes sense, start with a less ambitious project, such as reading "Learning Perl" (the Llama book), published by O'Reilly and Associates.


Dave

Replies are listed 'Best First'.
Re^2: Comparing files
by thor (Priest) on Jul 19, 2004 at 22:20 UTC
    If count == 30, you know that particular address was found in all 30 files...
    Almost. If count == 30, you know that the MAC showed up 30 times in the combined input. Could've been 30 times in the first file. If, however the OP knows that the MACs are unique within a given file (i.e. each MAC in a file appears only once), then the statement that "count == 30 implies it was found in all 30 files" is true.

    thor

      Good grief. Ok, well, if each file could contain the same mac address more than once, use a second hash to guarantee uniqueness per file. Or another approach would be to start with file one. Put all of its mac addresses into a hash, as keys. Then open file two. Delete any hash keys that aren't found in file two. Open file three. Delete any remaining hash keys that aren't found in file three. And so on... you get the idea. What's left at the end is your list of mac addresses that exist in all 30 files.


      Dave

        davido, I like your idea on how to do this. My questions are. How do you read a file into just the hash keys? How would I code, deleting hash keys from file1 that are not found in file2. Thanks