At 10:48 +0200 09/06/2011, venkates wrote: I need to retrieve all the gene entries to add it to a hash ref.
Your code is very fussy with all those substrings etc. What about something like this:
#!/usr/local/bin/perl use strict; my $read = 0; my @genes; my %hash; while (<DATA>){ chomp; $read = 1 if /^GENES/; $read = 0 unless /\s[A-Z]{3}:/; if ($read){ s/^GENES//; s/^\s+//; push @genes, $_; } } for (@genes){ my ($taxon_label, $gene_label) = split /:\s*/; $hash{$taxon_label} = $gene_label; } for (keys %hash){ print "Key: $_; Val: $hash{$_}\n"; } __DATA__ Your file contents here JD -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/