Hello,
I searched for a solution to my problem on this site already, but for some reason all nodes I found talked about the synetric difference of two arrays, which is not what I want. Maybe the problem has another name?
However, here is the problem. There are two arrays given (array references in that case):
my $before = [qw(1 2 3 4 5 6 7 8 9 10)]; my $after = [qw(2 3 4 5 1 6 7 8 9 10)];
The first array always looks the same (ascending numbers from $x to $x + $y). The second array is based on the first array, but one element inside it was moved. In the code example I gave it was element 0 (value 1) that was moved to position 5. The rest of the elements in $after moved up and down automatically.
The operation that was executed on the array could be expressed that way in perl:
my $element = splice(@$after, 0, 1); #remove element 0; splice(@$after, 4, 0, $element); #insert element at offset 4
The question is how to find out which element was moved to which offset, given that you only know the array $before and $after.
TIA, Flo
In reply to Difference between two arrays by rafl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |