Read each file into the following structure
my %file1_hosts = ( bobssite => { 'bobssite.autossl.net' => 1, 'www.bobssite.com' => 1, 'bobssite.dealer.net' => 1, }, billssite => { 'billssite.autossl.net' => 1, 'www.billssite.com' => 1, 'www.billsothersite.com' => 1, 'bobssite.dealer.net' => 1, }, );

Then you can easily compare the two files.

sub compare_aliases { my ($host, $file1_aliases, $file2_aliases) = @_ my %aliases = map { $_ => 1 } keys(%$file1_aliases), keys(%$file2_aliases); for my $alias (keys(%aliases)) { if (!$file1_aliases->{$alias}) { ... } elsif (!$file2_aliases->{$alias}) { ... } } } sub compare_hosts { my ($file1_hosts, $file2_hosts) = @_ my %hosts = map { $_ => 1 } keys(%$file1_hosts), keys(%$file2_hosts); for my $host (keys(%hosts)) { if (!$file1_hosts->{$host}) { ... } elsif (!$file2_hosts->{$host}) { ... } else { compare_aliases($host, $file1_hosts->{$host}, $file2_hosts->{$host}, ); } } } compare_hosts(\%file1_hosts, \%file2_hosts);

Update: Small bug fixes.


In reply to Re: Comparing Two Files by ikegami
in thread Comparing Two Files by walkingthecow

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.