The following code does what is required to be done however it keeps throwing an error => 'useless use of private variable in void context at line 21', this behavior showed up after I switched from using some disjointed if statements into a more compound given(){when(){}} construct. Frankly, I am at a total loss on how to resolve this, tried looking around for similar situations but the problem presentation was different and the replies just added to the confusion...

So fellow monks, I present before you the code after having become spent for my efforts with some records from the tab-delimited dataset, the combination of the code conditionals reflect whether or not some entries in the columns SNP, Allele1 and Allele2 are missing, and seeking your explanation on why this error arises and how to go about resolving it I afford you my appreciations and the kindest of gratitude ..

#!/usr/local/bin/perl use strict; use warnings; use Data::Dump qw(pp); use feature qw(switch say); my $path = "testSample.txt"; open(FH, $path) or die("error, $!\n"); my (%hetero, %homo, %unclassified); until(eof(FH)){ my ($file, $patientName, $panel, $snp, $allele1, $allele2, $siz +e1, $size2)= split "\t", <FH>; $snp ||='';$allele1 ||= ''; $allele2||=''; #if not initialized + set to '' chomp($snp); $snp = 'missed' if $snp eq ''; given($allele1, $allele2){ when($allele1 ne '' && $allele2 ne ''){constructHetero +($snp, $patientName, $allele1, $allele2)} when($allele1 ne '' && $allele2 eq ''){constructHomo(' +type1', $snp,$patientName, 'allele1', $allele1)} when($allele1 eq '' && $allele2 ne ''){constructHomo(' +type2', $snp,$patientName, 'allele2', $allele2)} when($allele1 eq '' && $allele2 eq ''){constructUnclas +sified($snp, $patientName)} } } sub constructHetero{ my ($snp, $patientName, $allele1, $allele2) = @_; $hetero{$snp}{$patientName}{'allele1'}=$allele1; $hetero{$snp}{$patientName}{'allele2'}=$allele2; $hetero{$snp}{$patientName}{'records'}++; $hetero{$snp}{'total_records'}++; }; sub constructHomo{ my ($type, $snp, $patientName, $alleleNumber,$allele)=@_; $homo{$type}{$snp}{$patientName}{$alleleNumber}=$allele; $homo{$type}{$snp}{$patientName}{'records'}++; $homo{$type}{$snp}{'total'}++; $homo{$type}{'total_records'}++; } sub constructUnclassified{ my($snp, $patientName)=@_; $unclassified{$snp}{$patientName}{'records'}++; $unclassified{$snp}{'total'}++; $unclassified{'total_records'}++; } #print pp(\%hetero); #print pp(\%homo); #print pp(\%unclassified);
testSample.txt Sample File Sample Name Panel SNP Allele 1 Allele 2 +Size 1 Size 2 011.fsa MS-039 Panel_3130 012.fsa MS-039 Panel_3130 31.76 014.fsa MS-291 Panel_3130 rs7577363 90.79 92.46 013.fsa MS-291 Panel_3130 rs7577363 006.fsa MS-290 Panel_3130 rs10735781 G 78.69 80. +31 005.fsa MS-290 Panel_3130 rs10735781 G 78.85 80. +32 011.fsa MS-039 Panel_3130 rs10735781 C 78.63 80. +1 001.fsa MS-148 Panel_3130 rs10735781 C G 78.57 80 +.2


Excellence is an Endeavor of Persistence. A Year-Old Monk :D .

In reply to 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.