Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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"; } }

Comment on Re: Diff between two arrays
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://270534]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2015-11-26 01:21 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (695 votes), past polls