|XP is just a number|
Difference between two arraysby rafl (Friar)
|on Mar 22, 2006 at 11:44 UTC||Need Help??|
rafl has asked for the
wisdom of the Perl Monks concerning the following question:
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):
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:
The question is how to find out which element was moved to which offset, given that you only know the array $before and $after.