Dear Monks,
I have written the following code that works OK (i.e. prints the correct results):
use stricts; use warnings; my $total_entry_non_barrel=''; my $aligns_non_barrel=''; my @split_aligns_non_barrel=(); my $separate_hit_non_barrel=''; my @split_hit_non_barrel=(); my $hit_line_non_barrel=''; my $hit_name_non_barrel=''; my $protein_non_barrel=''; my $stat_line_non_barrel=''; my @split_stats_non_barrel=(); my $score_non_barrel=''; my $conditional_evalue_non_barrel=''; my $env_start_non_barrel=''; my $env_end_non_barrel=''; my $i=0; my $k=0; $/="//\n"; while(<>) { $total_entry_non_barrel=$_; if($total_entry_non_barrel=~/^Query:\s+(.*?)\s\[L=(\d+)\]/m) { $protein_non_barrel=$1; } if ($total_entry_non_barrel!~/No hits detected/) { if($total_entry_non_barrel=~/Domain annotation for each model: +(.*)Internal pipeline statistics summary:/s) { $aligns_non_barrel=$1; @split_aligns_non_barrel=split(">> ", $aligns_non_barrel); for($i=0; $i<=$#split_aligns_non_barrel; $i++) { $separate_hit_non_barrel=$split_aligns_non_barrel[$i]; @split_hit_non_barrel=split(/\n/, $separate_hit_non_ba +rrel); $hit_line_non_barrel=$split_hit_non_barrel[0]; if($hit_line_non_barrel=~/^(.*?)\s+/) { $hit_name_non_barrel=$1; } #keep score, c-Evalue, env-start, env-end for each hit for($k=3; $k<=$#split_hit_non_barrel; $k++) { $stat_line_non_barrel=$split_hit_non_barrel[$k]; @split_stats_non_barrel=split(/\s+/, $stat_line_no +n_barrel); $score_non_barrel = $split_stats_non_barrel[3]; $conditional_evalue_non_barrel = $split_stats_non_ +barrel[5]; $env_start_non_barrel = $split_stats_non_barrel[13 +]; $env_end_non_barrel = $split_stats_non_barrel[14]; } if($hit_name_non_barrel=~/^PF\d+/) #it is a PFA +M-A hit, keep it if score >=TC { if($score_non_barrel>=$hash_pfamA_tc{$hit_name_non +_barrel}) { print $hit_name_non_barrel, "\t", $score_non_b +arrel, "\t", $conditional_evalue_non_barrel, "\t",$env_start_non_barr +el , "\t", $env_end_non_barrel, "\n"; } } elsif($hit_name_non_barrel=~/^PB\d+/) #it is a Pfam +B hit, keep it if Evalue<=1e-6 { if($conditional_evalue_non_barrel<=0.000001) { print $hit_name_non_barrel, "\t", $score_non_b +arrel, "\t", $conditional_evalue_non_barrel, "\t",$env_start_non_barr +el , "\t", $env_end_non_barrel, "\n"; } } } } } print "##\n"; } $/="\n";

However, when I run it, I get the warning:
Use of uninitialized value $hit_line_non_barrel in pattern match (m//) + at ttt.pl line 735

which is the line:
if($hit_line_non_barrel=~/^(.*?)\s+/)

in my program. What am I doing wrong?
Also, is there some tips you could tell me/re-write some commands etc that could make my code run faster?

In reply to Can you tell me why I get this error and if I can optimize my code somehow? by Anonymous Monk

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.