in reply to Re^2: Comparing an array against another array
in thread Comparing an array against another array

i have not referred to diff command of linux. please see this

my @a = ( 1, 2, 3 ); my @b = ( 3, 4, 5 ); my @diff_a = @a->diff(\@b) # [ 1, 2 ]

Replies are listed 'Best First'.
Re^4: Comparing an array against another array
by tobyink (Canon) on Jan 17, 2012 at 17:46 UTC

    You might not have, but I certainly did.

      sorry i missed it :)
Re^4: Comparing an array against another array
by jaldama (Acolyte) on Jan 17, 2012 at 19:06 UTC

    diff seems to be just what I need, thanks a lot. Is my only option perl5i to use the diff method? Or does anyone know why I'm getting this error? Can't call method "diff" without a package or object reference at backtick.pl line 8.

    my $hostname = $ARGV[0]; my @hostFiles = ("filecheck.pl", "hostscript.pl"); my @output =`ssh $hostname "cd Desktop; ls -a"`; my @diff = @hostFiles->diff(\@output); . . .
      use perl5i::latest; should do the trick.

      However, check your install log to see this module installed correctly. I finally had to force install it, due to an error in respect of the child method.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re^4: Comparing an array against another array
by jaldama (Acolyte) on Jan 18, 2012 at 14:25 UTC

    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?