You are missing a \s+ between a \w+ and \d+. Also, the whole part needs to be moved inside the loop.

#! /usr/bin/perl use warnings; use strict; open my $in, '<', '6U9D.pdb' or die $!; my %amino_acid_conversion = (ALA => 'A', TYR => 'Y', MET => 'M', LEU = +> 'L', CYS => 'C', GLY => 'G', ARG => 'R', ASN = +> 'N', ASP => 'D', GLN => 'Q', GLU => 'E', HIS = +> 'H', TRP => 'W', LYS => 'K', PHE => 'F', PRO = +> 'P', SER => 'S', THR => 'T', ILE => 'I', VAL = +> 'V'); my ($x, $y, $z) = (0, 0, 0); my $seq; while (<$in>) { if (/HEADER\s+(.*)/) { print ">$1\n"; } if (/^SEQRES\s+\d+\s+\w+\s+\d+\s+(.*)/) { $seq .= $1; } if (/^ATOM\s+\d+\s+\w+\s+\w+\s+\w+\s+\d+\s+(\S+)\s+(\S+)\s+(\S+)/) + { # ~~~ $x += $1; $y += $2; $z += $3; } } $seq =~ s/ //g; my $k = 0; for (my $i = 0; $i < length $seq; $i += 3) { my $triplet = substr $seq, $i, 3; if (exists $amino_acid_conversion{$triplet}) { print "$amino_acid_conversion{$triplet}"; } else { warn "Don't know how to convert '$triplet'.\n"; } $k++; } print "\n"; my $xgk = $x / $k; my $ygk = $y / $k; my $zgk = $z / $k; print "$xgk $ygk $zgk \n";

Note that I also turned strict and warnings on, used the 3-argument version of open without bareword filehandles, and checked its return value.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

In reply to Re: Issues regarding for loops and recursion by choroba
in thread Issues regarding for loops and recursion by Nickmofoe

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.