Hey monks! Again I ask for your sage wisdom on a question that has been perplexing me :)
I have two files, each of which have content like below:
<host id="bobssite" root-directory=".">
<host-alias>bobssite.autossl.net</host-alias>
<host-alias>www.bobssite.com</host-alias>
<host-alias>bobssite.dealer.net</host-alias>
</host>
<host id="billssite" root-directory=".">
<host-alias>billssite.autossl.net</host-alias>
<host-alias>www.billssite.com</host-alias>
<host-alias>www.billsothersite.com</host-alias>
<host-alias>bobssite.dealer.net</host-alias>
</host>
What I need to do is make sure that all host IDs that exist in file1 also exist in file2; AND for each host ID, all the host-aliases starting with www also match up. So, if www.site1.com and www.site2.com exist under host ID bobjones in file1, then bobjones must exist in file2 AND www.site1.com and www.site2.com must exist for the host ID bobjones.
Here is what I have so far, but then I am not sure how to compare the two. I know the code below is not much help, but I am really at a loss here.
#!/usr/bin/perl
use strict;
use warnings;
my %host_contents;
my $host_id;
while (<>) {
chomp;
if ($_ =~ /host id="(.*?)"/)
{
$host_id = $1;
}
if ($_ =~ m{<host-alias>(www.*?)</host-alias>})
{
push @{ $host_contents{$host_id} }, $1;
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.