my $file = get_file('pdb244l.ent'); #execute get_file subroutine for a + given input file ... my %record_types = parse_pdb_file($file); ... sub get_file { #to read from a file my ($input_file) = @_; open (IN, $input_file) || die "Cannot open $input_file for reading: +$OS_ERROR\n"; #open a filehandle or die my $sequence = ''; foreach my $line (<IN>) { #for each line in the filehandle IN $sequence .= $line # add (concatenate) to a string sequence } return $sequence; #return the string sequence close (IN); } ... sub parse_pdb_file { #to return a hash with keys that are record type +names and #values that are scalar containing lines for that + record type my @file = @_; my %record_types = (); foreach my $line (@file) { my ($record_type) = ($line =~ /^(\S+)/); #the pattern (\S+) is ret +urned and saved in $recordtype if (defined $record_types{$record_type} ) { $record_types{$record_type} .= $line; } else { $record_types{$record_type} = $line; #.= fails if a key is undef +ined } } return %record_types; }
You are reading in the file as a single block of data but then you are parsing the file as if it were separated into lines which means that you are only populating %record_types from the first line of the file.
In reply to Re: uninitialized split value
by jwkrahn
in thread uninitialized split value
by etheral
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |