What's going on: I've ssh'd onto my localhost, ls the desktop and taken those items and put them into an array I hardcoded a short list of items and I am comparing them with a hash to see if anything is missing from the host (See if something from a is NOT in b, and let me know). So after figuring that out, when I print out the "missing files" I get a bunch of duplicates (see below), not sure if that has to do with how the files are being checked in the loop, but I figured the best thing to do would be to just sort out the data and eliminate dupes. When I do THAT, and print out the fixed data, only one file is printing, two are missing. Any idea why?

#!/usr/bin/perl my $hostname = $ARGV[0]; my @hostFiles = ("filecheck.pl", "hostscript.pl", "awesomeness.txt +"); my @output =`ssh $hostname "cd Desktop; ls -a"`; my %comparison; for my $file (@hostFiles) { $comparison{$file} +=1; } for my $file (@output) { $comparison{$file} +=2 } for my $file (sort keys %comparison) { @missing = "$file\n" if $comparison{$file} ==1; #print "Extra file: $file\n" if $comparison{$file} ==2; print @missing; } my @checkedMissingFiles; foreach my $var ( @missing ){ if ( ! grep( /$var/, @checkedMissingFiles) ){ push( @checkedMissingFiles, $var ); } } print "\n\nThe missing Files without dups:\n @checkedMissingFiles +\n"; Password: awesomeness.txt ##This is what is printing after comparing the two + arrays awesomeness.txt filecheck.pl filecheck.pl filecheck.pl hostscript.pl hostscript.pl The missing Files without dups: ##what prints after weeding out duplic +ates hostscript.pl

In reply to Re^3: Comparing an array against another array by jaldama
in thread Comparing an array against another array by jaldama

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.