Hello, I am quite new to perl...I have written code to read in protein entries and save each in a seperate Fasta (.fa) file..I manage to save the header correctly in each .fa but I am unable to save the string! What am I doing wrong? Is the $pdbString variable out of scope? Or is there an error with the I/O?

This is the input: >d1dlwa_ a.1.1.1 slfeqlggqaavqavtaqfyangidmpnqtnktaaflcaalggpnawtgrnlkevhanmgvsnaqfttvi +ghlrsaltgagvaaalveqtvavaetvrgdvvtvniqadatvatff >d1uvyc1 b.1.1.1 niqadatvatffngidmpnqtnktaaflcaalggpnawtgrnlkevhanmgvsnaqfttvighlrsaltg +agvaaalveqtvavaetvrgdvvtvslfeqlggqaavqavtaqfya
My expected output (each in a .fa file): >1dl_a_ slfeqlggqaavqavtaqfyangidmpnqtnktaaflcaalggpnawtgrnlkevhanmgvsnaqfttvi +ghlrsaltgagvaaalveqtvavaetvrgdvvtvniqadatvatff >1uvy_c1 niqadatvatffngidmpnqtnktaaflcaalggpnawtgrnlkevhanmgvsnaqfttvighlrsaltg +agvaaalveqtvavaetvrgdvvtvslfeqlggqaavqavtaqfya

THIS IS MY CODE (if there is anyway to make this more compact, I appreciate it!)

#!/usr/bin/perl -w @PDBchain; @PDBcode; @pdbString; @SCOPclass; $count =0; #SET A COUNTER FOR NUMBER OF ENTRIES open (IN, "$ARGV[0]"); my @array; while (<IN>) { my $pdbId = $_; chomp($pdbId); push @array, $pdbId; print $pdbId; print "\n\n"; if ($pdbId =~/>d(\d\w\w\w)(\w[_\d])\s(\w)/) { $pdbString[$count] = ""; $PDBcode[$count]=$1; #SAVE PDB CODE print $PDBcode[$count]; print "\n"; $PDBchain[$count]=$2; #SAVE PDB CHAIN $SCOPclass[$count]=$3; #SAVE SCOP CLASS (A,B,C,D,E,F,G +) $count++; next; } else { $pdbString[$count].=$pdbId; next; } print $pdbString[$count]; #this prints the complete fasta sequ +ence per entry! print "\n\n"; } close IN; print "Total number of entries: ".$count. "\n"; #COUNT TOTAL NUMBER OF + PDBS REPRESENTED for(my $i=0;$i<$count;$i++) { open (OUT, ">>$PDBcode[$i]_$PDBchain[$i].fa"); print OUT ">",$PDBcode[$i], "_", $PDBchain[$i], "\n"; print OUT $pdbString[$i]; #WHY AM I UNABLE TO PRINT THE SEQUENCE HERE? close OUT; }

In reply to Problems with Variable Scope in Perl by InfoSeeker

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.