in reply to error returning hash value?

Your code and samples are too complicated. Try to simplify it: show only the relevant data (for example, 2 or 3 columns in the files should be enough). Also, remove any logic that's not relevant to your question.

To be able to run your code, I first had to remove the filenames from the downloaded files, I then got a lot of warnings (why didn't you turn them on?) like:

Odd number of elements in hash assignment at ./1.pl line 61. Use of uninitialized value in list assignment at ./1.pl line 61. Use of uninitialized value in join or string at ./1.pl line 83, <VAR> +line 7. Use of uninitialized value in join or string at ./1.pl line 83, <VAR> +line 7. Use of uninitialized value in join or string at ./1.pl line 83, <VAR> +line 7. Use of uninitialized value in join or string at ./1.pl line 83, <VAR> +line 7. Use of uninitialized value in join or string at ./1.pl line 83, <VAR> +line 7. Use of uninitialized value in join or string at ./1.pl line 83, <VAR> +line 7. Use of uninitialized value in join or string at ./1.pl line 83, <VAR> +line 7. Use of uninitialized value within %variants_geno in pattern match (m// +) at ./1.pl line 100, <VAR> line 7.

The first two lines can be fixed by replacing the line with

undef %variants_hash;

as the original was equivalent to

%variants_hash = ( undef => );

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: error returning hash value?
by drlecb (Initiate) on Jan 09, 2017 at 00:28 UTC

    Thank you for your time in replying. I'm sorry that I am not very good at asking questions; it isn't easy to know how much detail to include/not include. I always get it wrong :-(. I'll be honest in that I didn't understand what you meant by "To be able to run your code, I first had to remove the filenames from the downloaded files". I put the file names in because the code works on the principle that it reads in all .var files from the directory, so it made sense to me to put a header to say that they were named .var. Sorry if that was wrong.

    I have managed to get a bit further with it. I realised that i should have defined my hash as $zygos{$uniqlocus} = $zyg. I also noticed that $locus needed to be non-unique.

    I'll figure it out I'm sure. Thank you for your valiant efforts anyway!

      > I put the file names in

      Have you ever noticed the "download" link at the bottom of each code section? I clicked it to download the data including tabs, but they included the filenames. Don't make them part of the code section.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      I'm struggling to understand why if you want to 'merge' records from 3 files you are creating hash keys containing the filename ?

      $fields[2] = $file; my $locus = join "\t", @fields[0,1,2,3,4,5];

      From this output code, it looks like you want to create a 'cross tab' with HET/HOM derived from each file in a different column. Is that correct ?

      my $samples_list = join "\t", @samples; print OUT "CHROM POS ID REF ALT QUAL $samples_list

      update : my best guess at what you are trying to do.
      it isn't easy to know how much detail to include/not include

      Think about: what is the minimum amount of code and sample data needed so that others can reproduce the problem? For each line of code, try removing it - does the problem still exist? If yes, it was ok to remove that line, if the problem goes away, put the line back in. And if removing the line causes a compilation failure, fix that first. See also Short, Self-Contained, Correct Example.

      Hi drlecb. There are a few ways to include sample files with your program on Perlmonks. To include it like you did and have the Perl program still be runnable you can add __DATA__ or __END__ after your Perl program and anything after it will be treated as data or comments. Another way is to start a new code section for your sample file with  <c> ... </c> so that the monks can click download for the sample file.

      Here is an example of using __DATA__

      use warnings; use strict; while(<DATA>){ my $line = $_; print $line; } __DATA__ Line 1 Line 2 Line 3