in reply to finding neighbors of an element in arrays

What is a neighbour?

What is the output you get, and how is it different from the output you want?

Welcome, see The Perl Monks Guide to the Monastery, see How do I post a question effectively?

  • Comment on Re: finding neighbors of an element in arrays

Replies are listed 'Best First'.
Re^2: finding neighbors of an element in arrays
by Anonymous Monk on Jul 28, 2011 at 08:51 UTC

    for example PF05.3 has 3 neighbors in these three arrays ( PF11001.3, PF01,PF00389.24).or for example PF11001.3 has 3 neighbors (PF00389,PF02,PF05.3) and so on.out put is number of neighbors for each.thanks.

      And you just want the number? And this is a regular matrix without holes, i.e. all the arrays @domiansX have the same number of elements and no empty cells? Then all elements inside the matrix have 4 neighbors, all elements at the sides have 3 and all elements at the edge of the matrix have 2 neighbors.

      If your matrix has holes, you might preset each element to have 4 neighbors and subtract 1 from every neighbor of a hole

      PS: It might be easier to store the matrix as a two-dimensional array instead of having each row in a separate array. Check out perllol how to use two-dim arrays aka ArrayOfArrays

      Ok, misread your examples. But I still don't get it, why is PF00389.24 not a neighbor of PF11001.3 ? Maybe you could define neighborhood directly instead of using examples

        order in array was important and i arranged them in special order.assume @domain={A,B,C,D},B is a neighbor for A and A and C are neighbors for B.neighbors are elements around an specific element.thanks a lot for your help.

        my @domains1=('PF05.3','PF11001.3','PF00389.24','PF10417.3'); my @domains2=('PF01','PF02','PF11001.3','PF00389'); my @domains3=('PF00389.24','PF05.3','PF01','PF00389'); as you see,for example PF00389.24 in @domains1 has two neighbor 'PF11001.3','PF10417.3' and in @domain2 nothing and in @domain3 one(PF05.3).