#!/USR/BIN/PErl use strict; use warnings; #use TEXT::CSV_XS; open(DATA1,"<Switcher.properties"); open(DATA2,"<SwitcherNew.properties"); open(DATA3,">CMP.csv"); my %Hash1 = (); my %Hash2 = (); my %MissHash1 = (); my %MissHash2 = (); while(<DATA1>) { chomp; my ($key, $values) = split "=", $_, 2; my @values = split ",", $values; $Hash1{$key} = \@values; } while(<DATA2>) { chomp; my ($key, $values) = split "=", $_, 2; my @values = split ",", $values; $Hash2{$key} = \@values; } print "\n\n First Hash map \n"; print "\n\n Key : value(s)\n\n"; foreach my $key (sort keys %Hash1) { print "$key:\n "; foreach my $value (@{ $Hash1{$key} }) { print "\t$value\n"; } } print "\n\n Second Hash map \n"; print "\n\n Key : value(s)\n\n"; foreach my $key (sort keys %Hash2) { print "$key:\n "; foreach my $value (@{ $Hash2{$key} }) { print "\t$value\n"; } } ###### print "\n\nThese are the differences in values for the same keys \n +\n"; print DATA3 "\n\nThese are the differences in values for the same keys + \n\n"; print DATA3 "\n\nKey --> values \n\n"; foreach my $key (keys %Hash1) { foreach my $key1 (keys %Hash2) { if (!exists $Hash1{$key1}) { my @Mvalues= @{ $Hash2{$key1} } ; $MissHash1{$key1} = \@Mvalues ; } elsif ($key eq $key1) { if (@{ $Hash1{$key} } eq @{ $Hash2{$key1} }) { #print "\n Similarities --> Hash1 value :@{ $Hash1{$key} } Hash2 valu +e :@{ $Hash2{$key1} }\n"; } else { print "\n $key : \nHash1 @{ $Hash1{$key} } \nHash2 @{ $Hash2{$key1} + }\n"; print DATA3 "\n $key :\n"; print DATA3 " @{ $Hash1{$key} } \n @{ $Hash2 +{$key1} }\n"; my @m= @{ $Hash1{$key} }; my @n=@{ $Hash2{$key1} }; print "\n The no of comma separated values : $m : $n \n"; my $count=0; foreach my $m1 (@m) { foreach my $n1 (@n) { if ($m1 eq $n1) { ++$count; } else { } } } print "\ncount ---> $count\n"; } } }} foreach my $key1 (keys %Hash2) { foreach my $key (keys %Hash1) { if(!exists $Hash2{$key}) { my @Mvalues= @{ $Hash1{$key}}; $MissHash2{$key} = \@Mvalues ; } } } print "\n\n These are the keys Added in Hash1 \n"; print DATA3 "\n\n These are the Added keys in Hash1 \n"; foreach my $key ( keys %MissHash2) { print DATA3 "\n$key : "; print "\n$key : "; foreach my $value (@{ $MissHash2{$key} }) { print DATA3 "\n $value"; print "\n\t$value"; } } print "\n\n These are the keys Added in Hash2 \n"; print DATA3 "\n\n These are the Added keys in Hash2 \n"; foreach my $key ( keys %MissHash1) { print DATA3 "\n$key : "; print "\n$key : "; foreach my $value (@{ $MissHash1{$key} }) { print DATA3 "\n $value"; print "\n\t$value"; } } print "\n\n"; print DATA3 "\n\n"; close(DATA3); close(DATA1); close(DATA2);

In reply to Re^11: How to assign an array to a value in hash? by vukotid
in thread Re: How to assign an array to a value in hash? by vukotid

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.