Hello, Perl Monks! I've fixed the code I'm about to show you, but I cannot understand why the original code was not working. For background, this script used to run just fine, but now, without explicitly defining the variables, it returns an undefined %chrsize hash. I've inherited this script and I've been tasked with fixing it. It was written without "use warning" and "use strict". here is the original code:

use File::Basename; my $filename=fileparse($ARGV[0]); $win=1000; # window size 1kb $L=`/scratch/xli91_lab/bin/rpyc/sumcol $ARGV[2] 2`; # total nt of geno +me excluding chrUext and chrM $N=$L/$win; $ratio=$ARGV[1]*0.01; open IN,$ARGV[2]; while(<IN>) #there was no $_[1]; it was undef/blank. After explicitly +declaring/storing in @array, it worked { chomp; split(/\t/); $chrsize{$_[0]}=int($_[1]/$win); }

Here is how I fixed it:

use File::Basename; my $filename=fileparse($ARGV[0]); $win=1000; # window size 1kb $L=`/scratch/xli91_lab/bin/rpyc/sumcol $ARGV[2] 2`; # total nt of geno +me excluding chrUext and chrM $N=$L/$win; $ratio=$ARGV[1]*0.01; open IN,$ARGV[2]; while(<IN>) { chomp(my $line= $_); my @array = split(/\t/, $line); print"$array[0]\n"; #array[1] are numbers #array[2] are chr names $chrsize{$array[0]}=int($array[1]/$win); }

On an unrelated note: This is part of a perl script that USED to work without throwing errors until a system security update on our university's linux cluster. on an unrelated note, do you believe that the larger script may be throwing errors now due to permissions issues? Why else would a working script suddenly stop working after tightening security?


In reply to What is the logical error here (Fixed, but I want to understand) by hghosh

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.