Hi,
I have two list like this:
a1 = [2,5,7,9,10]
a2 = [1,4,7,8,10]
first I tried to find the first common element by perl script:
#!/usr/bin/perl -w
use strict;
use warnings;
my $index1 = length(@a1)-1;
my $index2 = length(@a2)-1;
my $commonElement = "";
while ($a1[$index1] eq $a2[$index2]){
$commonElement = $a1[$index1];
$index1--;
$index2--;
}
return "$commonElement\n";
if I want to find get distance simultaneously, how can do that? for instance in this exapmle for both list should be 3.
I wrote this but it doesn't work:
$index1 = 1;
$index2 =1;
if ($a1[$index1] ne $a2[$index2]){
$index1++;
$index2++;
}elsif ($a1[$index1] eq $a2[$index2]){
return $index1, $index2;
exit;
}
Any response would be appreciated.
I have two list like this:
a1 = [2,5,7,9,10]
a2 = [1,4,7,8,10]
first I tried to find the first common element by perl script:
#!/usr/bin/perl -w
use strict;
use warnings;
my $index1 = length(@a1)-1;
my $index2 = length(@a2)-1;
my $commonElement = "";
while ($a1[$index1] eq $a2[$index2]){
$commonElement = $a1[$index1];
$index1--;
$index2--;
}
return "$commonElement\n";
if I want to find get distance simultaneously, how can do that? for instance in this exapmle for both list should be 3.
I wrote this but it doesn't work:
$index1 = 1;
$index2 =1;
if ($a1[$index1] ne $a2[$index2]){
$index1++;
$index2++;
}elsif ($a1[$index1] eq $a2[$index2]){
return $index1, $index2;
exit;
}
Any response would be appreciated.
Comment