i try to read two different files into a array and compare
both and print difference between fil0 > file1 (both files
have a identical construction, see __DATA__

Problem:
--------
-Need to compare EntityName & m_LocalNbrPhysAddr for every
element (each data element starts with { and ends with },
at the moment i compare each key seperately,and print out the difference.

Finale solution i need:
-----------------------
-read in EntityName,m_LocalNbrPhysAddr,m_ConnectedTo between the { } data context into
a hash from file0 and do the same with the file1 and
compare both
THANKS FOR ANY SUPPORT !

my lame code:
-------------

for my $data (<FILE34>) { foreach my $line (split /};/, $data) { next if $line eq ''; next if $line =~ m/^\s+$/; next if $line =~ /^\{$/; next if $line =~ /^\}$/; #$line =~ s/\s+//g; $line =~ s/\;//g; my ($key, $value) = split(/'/, $line); if ( $key =~ /EntityName/ ) { next if $value eq ''; $value =~ s/\.domain\.net//g; $value =~ s/\s+//g; push @entity34_name, ($key.$value); } if ( $key =~ /m_LocalNbrPhysAddr/ ) { next if $value eq ''; $value =~ s/\s+//g; push @entity34_mac, ($key.$value) } if ( $key =~ /m_ConnectedTo/ ) { next if $value eq ''; $value =~ s/\s+//g; push @entity34_connectedTo, ($key.$value) } } } close(FILE34); open(FILE35, "<$dump3_5") || die "Cannot open file: $!"; for my $data (<FILE35>) { foreach my $line (split /};/, $data) { next if $line eq ''; next if $line =~ m/^\s+$/; next if $line =~ /^\{$/; next if $line =~ /^\}$/; #$line =~ s/\s+//g; $line =~ s/\;//g; my ($key, $value) = split(/'/, $line); if ( $key =~ /EntityName/ ) { next if $value eq ''; $value =~ s/\s+//g; $value =~ s/\.cablecom\.net//g; push @entity35_name, ($key.$value); } if ( $key =~ /m_LocalNbrPhysAddr/ ) { next if $value eq ''; $value =~ s/\s+//g; push @entity35_mac, ($key.$value) } if ( $key =~ /m_ConnectedTo/ ) { next if $value eq ''; $value =~ s/\s+//g; push @entity35_connectedTo, ($key.$value) } } } close(FILE35); ##print difference foreach (@entity35_name) { $seen{$_}++; } foreach (@entity35_mac) { $seen{$_}++; } foreach (@entity35_connectedTo) { $seen{$_}++; } ### foreach (@entity34_name) { print OUTPUT "$_\n" unless $seen{$_}; } foreach (@entity34_mac) { print OUTPUT "$_\n" unless $seen{$_}; } foreach (@entity34_connectedTo) { print OUTPUT "$_\n" unless $seen{$_}; } __DATA__ { EntityName='dummy0.domain.net[ Fa0/1 ]'; m_LocalNbrPhysAddr='00:0C:85:F4:66:01'; } { EntityName='dummy2[ Fa0/0 ]'; m_LocalNbrPhysAddr='00:0C:85:F4:66:00'; m_ConnectedTo=['dummyXX.domain.net[ Gi0/12 ]']; } { EntityName='dummy3.domain.net[ Fa0/0 ]'; m_LocalNbrPhysAddr='00:0C:85:F4:66:00'; m_ConnectedTo=['dummyYY.domain.net[ Gi0/12 ], dummyXX. +domain.net[ Fa0/12 ]'';

20050107 Edit by castaway: Changed title from 'compare and sort hashes'


In reply to Compare and Sort Arrays by perl_lamer

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.