walkingthecow has asked for the wisdom of the Perl Monks concerning the following question:
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.<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>
#!/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; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Comparing Two Files
by ikegami (Patriarch) on Jun 29, 2010 at 23:09 UTC | |
by happy.barney (Friar) on Jul 01, 2010 at 09:59 UTC | |
Re: Comparing Two Files
by davido (Cardinal) on Jun 29, 2010 at 23:18 UTC | |
Re: Comparing Two Files
by ssandv (Hermit) on Jun 29, 2010 at 23:15 UTC | |
Re: Comparing Two Files
by walkingthecow (Friar) on Jun 30, 2010 at 16:18 UTC | |
Re: Comparing Two Files
by Proclus (Beadle) on Jul 01, 2010 at 09:15 UTC |