in reply to Comparing an array against another array

perldoc -q intersect

Replies are listed 'Best First'.
Re^2: Comparing an array against another array
by jaldama (Acolyte) on Jan 17, 2012 at 17:07 UTC
    How would I use something like this, though, to see what is in A but not in B? It doesn't matter if something else is in B that isn't in A.
      #!/usr/bin/perl @A = qw/dog cat squirrel wolf/; @B = qw/dog cat monkey donkey/; undef @C{ @A }; delete @C{ @B }; say for keys %C; __END__ prints: squirrel wolf

      I am using List::Compare, seemed like a good way to compare these two arrays. My comparing method doesn't seem to be producing the result it should be, though.. Would it be because doing ls -a stores each item on a new line? To clarify, here is the code:

      #!/usr/bin/perl use List::Compare; my $hostname = $ARGV[0]; my @hostFiles = qw/filecheck.pl hostscript.pl awesomeness.txt/; my @output =`ssh $hostname "cd Desktop; ls -a"`; $lc = List::Compare->new(\@hostFiles, \@output); @Lonly = $lc->get_unique; print @Lonly;

      And this is what prints out

      Password: awesomeness.txt filecheck.pl hostscript.pl

      So then I printed out what's on my desktop along with whatever @Lonly is saving as:

      awesomeness.txt filecheck.pl hostscript.pl . .. .DS_Store .localized PERL TESTS compare.pl greptest.pl hostfilecheck.pl hostscript.pl

      Why would @Loutput still be showing hostscript.pl if that's on the Desktop?