in reply to Re: Concatenating text for a hash problem
in thread Concatenating text for a hash problem
We came up with nearly the exact same solution. I believe you can eliminate $val, however, by operating directly on the hash value.
use strict; use warnings; my %hash; my $id; while( my $line = <DATA> ) { chomp $line; # if( $line =~ m/^>(.+?) / ) # changed to \S if( $line =~ m/^>(\S+)/ ) { $id = $1; } else { $hash{$id} .= $line; } }
ewijaya, if you are trying to read sequence files in fasta format, you might want to look at bioperl's Bio::SeqIO class.
Update: ihb made a good point about the regex. I made the assumption (based on the example data) that a space will always follow the sequence ID, but that may not always be true. Therefore, ihb's regex is a bit safer for that reason (although you should keep in mind that \w will not match '.' or '-', so \S is probably better).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Concatenating text for a hash problem
by ihb (Deacon) on Oct 15, 2004 at 06:38 UTC |