You did not specify what to do if the file is missing in one of the hashes. The following code informs you about all the possible situations:
#!/usr/bin/perl
use warnings;
use strict;
use feature qw(say);
my %size1 = ( 'autorun.inf' => 42,
'autoexec.bat' => 118,
'eicar.zip' => 186,
);
my %size2 = ( 'autorun.inf' => 42,
'autoexec.bat' => 119,
'ibmbio.com' => 234186,
);
my %files;
undef @files{keys %size1, keys %size2};
for my $file (keys %files) {
delete $files{$file}, next if exists $size1{$file}
and exists $size2{$file}
and $size1{$file} == $size2{$file};
$files{$file} = 'Missing in 1', next unless exists $size1{$file};
$files{$file} = 'Missing in 2', next unless exists $size2{$file};
$files{$file} = 'Size changed';
}
for my $file (keys %files) {
say "$file\t$files{$file}";
}
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.