Ed Christian <[EMAIL PROTECTED]> wrote:
: While the foreach is certainly more wasteful, why in
: the world would you re-initialize and re-open the
: file multiple times? Why not just open the file once
: and iterate over the file, comparing each line of
: the file to each of the keys in the %input hash?
:
: # My idea
: while (defined(my $line = <DATA>)) {
: foreach my $gene (sort keys %genedex) {
: if ($line =~ /$gene/) {
: ($probe_id) = split(/\s/,$line,2);
: print "$gene\t$probe_id\t$genedex{$gene}\n";
: }
: }
: }
I didn't test it, but ...
my $gene_regex = qr|join '|', keys %genedex|;
while ( defined( my $line = <DATA> ) ) {
next unless $line =~ /($gene_regex)/;
my $gene = $1;
# The split extracts the probe id
printf "%s\t%s\t%s\n",
$gene, ( split /\s/, $line )[0], $genedex{$gene};
}
HTH,
Charles K. Clarkson
--
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>