in reply to Getting an unknown error
Hello andybshaker,
Others have answered your immediate question, but I want to comment on this part of your code:
open(IN, "<$file") or die "Cannot open file $file\n"; my @lines = <IN>; foreach $1 (@lines){ chomp($1); my %columns = split(">", $1); } close(IN);
(I have reformatted it a little to make it clearer.) First, the use of $1 as a loop variable is — well, unusual, to say the least. Normally, $1 contains the first matched string in the last regular expression match. In idiomatic Perl, the variable $_ is used implicitly:
foreach (@lines){ chomp; my %columns = split(">"); }
But second, and much more importantly, this foreach loop does literally nothing. You create a lexical variable %columns and fill it with split; then re-create it on the next iteration of the loop; and so on. And when the loop ends, the variable — having been declared within the scope of the loop — goes out of scope and is (eventually) garbage-collected. The contents of the file remain unchanged.
And a final point: Please, please get into the habit of using a sane code formatting (indenting) style for nested loops. For example:
foreach my $G (@Genes){ for my $x (0 .. $#ptt){ if ($ptt[$x] =~ /$G/){ push(@Coordinates,"$ptt[$x]"); print "$ptt[$x]\n"; } } }
Why make your code harder to read than it needs to be? The maintenance programmer who comes to look at the code in six months time may well be you!
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting an unknown error
by AnomalousMonk (Archbishop) on Apr 23, 2015 at 16:11 UTC | |
by ww (Archbishop) on Apr 23, 2015 at 18:14 UTC | |
by AnomalousMonk (Archbishop) on Apr 23, 2015 at 19:36 UTC | |
by ww (Archbishop) on Apr 23, 2015 at 22:11 UTC | |
by AnomalousMonk (Archbishop) on Apr 24, 2015 at 01:57 UTC | |
|