Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Diff between two arrays

by pboin (Deacon)
on Jul 01, 2003 at 16:42 UTC ( #270534=note: print w/replies, xml ) Need Help??

in reply to Diff between two arrays

I believe the following is a working solution.

However, the problem of equating burritos to tacos is a different question IMO. I have not attempted that at all, but you'd need a 'dictionary' of equivalents I think.

This is my first attempt to reply with a working solution, so thank you for your patience. (Comments requested and appreciated.

my @array1=qw(I like to eat tacos); my @array2=qw(Do you like to eat burritoes); my @diff = &get_diff(\@array1,\@array2); sub get_diff(){ my $slave = shift(@_); # reference to @array1 my $master = shift(@_); # reference to @array2 # loop through @master for (my $m = 0; $m < scalar(@$master); $m++){ my $matchpos = 0; # loop through @slave for (my $s = 0; $s < scalar(@$slave); $s++){ # is this word found? if (@$master[$m] eq @$slave[$s]){ $matchpos = $s; last; } } @diff = (@$master[$m],$m,$matchpos); print "@$master[$m],$m,$matchpos\n"; } }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://270534]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2017-06-26 17:59 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (585 votes). Check out past polls.