in reply to Re: Need to Create an Array of Differences
in thread Need to Create an Array of Differences

ther's a better way to use grep...

my @difference =  grep /^@a1/, @a2;

#example of sub...

my $difference = diff(\@a1,\@a2);

sub diff {
    my @diff =  grep /[^@{$_[0]}]/, @{$_1};
    return \@diff;
}

Marco (nemux)
Bye.
  • Comment on Re^2: Need to Create an Array of Differences

Replies are listed 'Best First'.
Re^3: Need to Create an Array of Differences
by Anonymous Monk on Dec 16, 2004 at 15:54 UTC
    sorry ... is impossible to see in my previous message the -> [] 
    
    then with square brackets visible is :
    
    sub diff_2 {
        my @diff =  grep /[[^@{$_[0]]}]/, @{$_[1]};
        return \@diff;
    }
    
    Marco
    
    
      Better?
      If that worked, it wouldn't be semantically the same as Aristotle's, Zaxo's, or my reply. Nor of the perlfaq or tachyon's (which show a difference of both arrays).

      Did you test your code? It is a nice thought, however, I cannot make that work on 5.6.1, 5.8.1, or 5.8.5
      For a simple array of int's @diff is always undef.
      For an array containing scalars I get "Invalid range in regex" error, which is what I expect.

      -xtype