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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.