in reply to finding neighbors of an element in arrays
I'm not sure what you are trying to do, but there are a number of obvious errors in your code.
If resolving the errors pointed out above doesn't fix your problem then you should show us a small sample of your input data and the output you expect from it. Maybe though you want to achieve something like:
use strict; use warnings; my $list = <<LIST; PF10417.3 PF11001.3 PF05.3 LIST 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'); my %neighbours; for my $domain (\@domains1, \@domains2, \@domains3) { for my $idx (0 .. $#$domain) { my @near = grep {$_ >= 0 && $_ <= $#$domain} $idx - 1, $idx + +1; push @{$neighbours{$domain->[$idx]}}, map {$domain->[$_]} @nea +r; } } open my $inList, '<', \$list or die "cannot open 'domainlist'becuase:$ +!"; while (defined (my $domain = <$inList>)) { chomp $domain; print "Domain $domain has neighbours: @{$neighbours{$domain}}\n"; }
Prints:
Domain PF10417.3 has neighbours: PF00389.24 Domain PF11001.3 has neighbours: PF05.3 PF00389.24 PF02 PF00389 Domain PF05.3 has neighbours: PF11001.3 PF00389.24 PF01
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: finding neighbors of an element in arrays
by Anonymous Monk on Jul 28, 2011 at 13:14 UTC | |
by GrandFather (Saint) on Jul 28, 2011 at 20:45 UTC |