persianswallow has asked for the wisdom of the Perl Monks concerning the following question:
hi friends.in this following code i want to create list instead of my $list in the script from a text file that has a word in each line.please help me.
#!/usr/bin/perl 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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: list from file
by Not_a_Number (Prior) on Jul 29, 2011 at 21:37 UTC | |
by persianswallow (Novice) on Jul 29, 2011 at 21:45 UTC | |
by ww (Archbishop) on Jul 29, 2011 at 22:01 UTC | |
by Not_a_Number (Prior) on Jul 29, 2011 at 22:18 UTC | |
by planetscape (Chancellor) on Jul 30, 2011 at 12:50 UTC | |
|
Re: list from file
by GrandFather (Saint) on Jul 29, 2011 at 22:00 UTC | |
by persianswallow (Novice) on Jul 29, 2011 at 22:12 UTC | |
by persianswallow (Novice) on Jul 29, 2011 at 23:33 UTC |