Do you suppose the backslash at the end of line 1 has anything to do with it?

Update: There's a closing curly missing at the end of the main line, before the first subroutine. And what's the '+' after 'size2' in the declaration line? That was caused by PerlMonks line-wrapping.

update 2: SOLVED! given() takes a single variable or value, and assigns it to $_, so that in the various when() clauses, you can test $_ with various values / regex / routines. I'm quessing $_ is the private variable which is not used.

You don't need to assign empty strings to the variables, nor do you need to compare against an empty string, undef or empty string are both 'false' in a boolean concept, that's a design feature, not an accident. Also, When reading a file, just read into a buffer variable, the read operation assigns undef to the buffer, ending the loop. I chomp the line when read, and skip empty lines, because I was getting an empty line at the end of the data file. Also, I use ||= to assign 'missed' to $snp if it doesn't have a string value.

I'm not a biologist, but 'homo' means 'the same', 'hetero' means 'different'. So I'm thinking when allele1 and allele2 are both set, it should be 'homo', and 'hetero' should apply when only one is set.

while ( my $line = <FH> ) { chomp $line; next unless length $line; my ( $file, $patientName, $panel, $snp, $allele1, $allele2, $size1 +, $size2 ) = split "\t", $line; $snp ||= 'missed'; if ( $allele1 && $allele2 ) { constructHetero( $snp, $patientName, $allele1, $allele2 ) } elsif ( $allele1 && not $allele2 ) { constructHomo( 'type1', $snp, $patientName, 'allele1', $allele +1 ) } elsif ( not $allele1 && $allele2 ) { constructHomo( 'type2', $snp, $patientName, 'allele2', $allele +2 ) } elsif ( not $allele1 && not $allele2) { constructUnclassified( $snp, $patientName ) } }

update 3 : Changed from '!' to 'not' for negation, better visibility.

As Occam said: Entia non sunt multiplicanda praeter necessitatem.


In reply to Re: Text Analysis: given(){when(){}} block throws a 'useless use of private variable...etc' error by TomDLux
in thread Text Analysis: given(){when(){}} block throws a 'useless use of private variable...etc' error by biohisham

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.