in reply to Re^2: finding neighbors of an element in arrays
in thread finding neighbors of an element in arrays
The loop iterates over all the element indexes in the current domain array. For each index it generates a list containing the index before and after the current index: $idx - 1, $idx + 1. The grep then filters the list to give a list containing just valid indexes (it removes -1 or scalar @$domain values if present).
That leaves the neighbour indexes for the current index in @near. The map turns the neighbour indexes into a list of neighbour values. The push pushes the list into the array referenced by the hash entry for the value at the current index.
Looking back over that description I'm glad to be using Perl rather than COBOL!
|
|---|