in reply to Can't use string ("0") as a HASH ref while "strict refs" problem

You have not shown us a small, self-contained example that reproduces the problem.

Most likely, the problem is that your datastructure is not what you think it is, and/or it doesn't match the way your code tries to use it. In the code path leading up to the problematic line, you output the variables $RC and< c>$cds</c> and others. Maybe you can share the values that you see there with us.

Also very good for visualizing a data structure is the module Data::Dumper. Print out what Perl has as your data structure using

use Data::Dumper; print Dumper \%hash_geno_group;

If the output from Data::Dumper is too large, reduce the data you store into %hash_geno_group and store only the data where the problem happens.

Replies are listed 'Best First'.
Re^2: Can't use string ("0") as a HASH ref while "strict refs" problem
by etricaen (Novice) on Apr 12, 2016 at 09:54 UTC

    this a output of part of the dumper :

     print Dumper(\%hash_geno_group{$sample_geno_group});

    after :

     next if ($cds eq "sample");

    this my output :

    'XM_010928396.1 ' => { 'ambigu' => 156, 'BC11_III_.RG' => 75, 'rc' => 195, 'BC11_II_.RG' => 120 }, 'XM_010930511.1 ' => { 'BC11_II_.RG' => 258, 'ambigu' => 4, 'rc' => 1074, 'BC11_III_.RG' => 816 }, 'XM_010922249.1 ' => { 'BC11_II_.RG' => 0, 'ambigu' => 0, 'BC11_III_.RG' => 0, 'rc' => 0 }, 'XM_010912985.1 ' => { 'BC11_II_.RG' => 0, 'rc' => 0, 'ambigu' => 0 }, 'XM_010935705.1 ' => { 'BC11_II_.RG' => 0, 'ambigu' => 0, 'rc' => 0, 'BC11_III_.RG' => 0 }, 'XM_010939661.1 ' => { 'ambigu' => 0, 'BC11_III_.RG' => 0, 'rc' => 0, 'BC11_II_.RG' => 0 }, 'XM_010916522.1 ' => { 'BC11_II_.RG' => 0, 'rc' => 0, 'BC11_III_.RG' => 0, 'ambigu' => 0 }, 'XM_010930873.1 ' => { 'BC11_II_.RG' => 0, 'ambigu' => 0, 'rc' => 0, 'BC11_III_.RG' => 0 }, 'XM_010926039.1 ' => { 'BC11_II_.RG' => 0, 'BC11_III_.RG' => 0, 'rc' => 0, 'ambigu' => 0 }, 'XM_010928394.1 ' => { 'BC11_II_.RG' => 0, 'ambigu' => 0, 'BC11_III_.RG' => 0, 'rc' => 0 } }; Can't use string ("75") as a HASH ref while "strict refs" in use at te +st_fontion4.pl line 118.

    can you see where is my problem ?

      Perl already tells you where your problem is. In line 118.

      You haven't shown us the values of $cds or $RC, and you don't show us the line 118 from your script.

      From the error message Can't use string ("75") as a HASH ref and from the data you've showed, I can guess that your script tries to use the 75 from this hash entry:

      'XM_010928396.1 ' => { 'ambigu' => 156, 'BC11_III_.RG' => 75, 'rc' => 195, 'BC11_II_.RG' => 120 },

      Maybe you want to rerun your script using only this data, and then you should easily find out where your problem is.

      Maybe you want to reduce your deep diving through the data structure into several steps, giving Perl the chance to be more to the point with its error messages:

      # Convert this: values %{$hash_geno_group{$sample_geno_group}{$cds}{"rc"}} # to this: my $sample_geno_group_ref = $hash_geno_group{$sample_geno_group}; my $sample_cds = $sample_geno_group_ref->{$cds}; my $sample_rc = $sample_cds->{"rc"};

      Maybe also output the Dumper of each step so you can see where you are within your data structure.

        i fix my problem thanks for all this is the solution i found:

        foreach my $sample_geno_group(keys(%hash_geno_group)) { print $sample_geno_group. "\n"; foreach my $cds (keys %{$hash_geno_group{$sample_geno_group}}) { print "cds ".$cds. "\n"; next if ($cds eq "sample"); my $RC = 0; $RC += $hash_geno_group{$sample_geno_group}{$cds}{"rc"}; print "rc ".$RC. "\n"; #verification du nombre minimun de reads pour chaque groupe ge +notypique if ($RC < $seuil_min_classe) {