http://www.perlmonks.org?node_id=981449


in reply to Re: hash with both values and keys unique to each other
in thread hash with both values and keys unique to each other

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^2: hash with both values and keys unique to each other

Replies are listed 'Best First'.
Re^3: hash with both values and keys unique to each other (pseudocode)
by Tanktalus (Canon) on Jul 12, 2012 at 19:53 UTC

    There are some standard ways to ask questions that elicit positive responses.

    You can use pseudo-code. If you do so, under no circumstances should it look like something a noob whipped up without any thought. One good way to do this is not to write it in any programming language you know. However, even here, variable names must be followable.

    Or you can use a short example of your code. It must be compilable (unless your question is "why doesn't this compile?"). It must be runnable. And it must produce the error scenario you describe. This makes it easy for those who may have an idea on how to help you to actually, you know, help. They can load your code into their debugger, go at it line by line, and possibly give you some insight into your issue. It also helps if you follow some sort of coding standards. It doesn't have to be the One True Brace Style, but it has to be something consistent and has to lend itself to being readable to others. If this all means you need to heavily edit your code before posting, it will at least be obvious that you put some effort in to being helped, making it more likely others will help you. Or at least it won't look like a big ball of mud and that you put no effort into being helped.

    Of course, when you do all that, you'll start to find that you solve your own problem. It might be more work, but it'll solve your issue faster than waiting for some random monk to happen upon your node and take the challenge of helping you with a reply.

Re^3: hash with both values and keys unique to each other
by Anonymous Monk on Jul 13, 2012 at 15:26 UTC

    Guys this is just a pseudocode to make you understand what the problem really is.

    Pseudocode with  use strict; use warnings;?

    Might as well make it real code

Re^3: hash with both values and keys unique to each other
by perlkhan77 (Acolyte) on Jul 12, 2012 at 17:15 UTC

    Following is the real code :

    use strict; use Time::HiRes; my $start_time = [Time::HiRes::gettimeofday()]; my (@coordinates,%hash_chr,%HOA,%HOH,%hash_line) = (); open FILE,"GmGm.recent.gff"; while(my $line=<FILE>){ chomp $line; my %seen = (); if($line=~/^(Gm\d{1,})\trecent_duplication\tsyntenic_region\t(\d{1,})\ +t(\d{1,})\t.*\tID\=\w{1,}_Gm\d{1,}\.(Gm\d{1,}.*)\;median_Ks=(.*)\;mat +ches\=(Gm\d{1,}\:\d{1,}\.\.\d{1,})/) { my $chr1 = "$1:$2..$3"; my $ks_val = $5; my $chr2 = $6; if ((exists $hash_chr{$chr2})&&($ks_val > 0.4)){ next; } else{ $hash_chr{$chr1}=$chr2; } } } close FILE;

    And this is how the file looks like

    Gm01 recent_duplication syntenic_region 170877 269340 1 +79 - . ID=A_Gm01.Gm08.2.-;median_Ks=0.1101;matches=Gm08:4628 +8465..46349001 Gm08 recent_duplication syntenic_region 46288465 46349001 + 179 - . ID=B_Gm01.Gm08.2.-;median_Ks=0.1101;matches=Gm01: +170877..269340

      As a side note, you can clean up that regex quite a bit by using + instead of {1,}, and not escaping colons, semi-colons, and equals:

      #if($line=~/^(Gm\d{1,})\trecent_duplication\tsyntenic_region\t(\d{1 +,})\t(\d{1,})\t.*\tID\=\w{1,}_Gm\d{1,}\.(Gm\d{1,}.*)\;median_Ks=(.*)\ +;matches\=(Gm\d{1,}\:\d{1,}\.\.\d{1,})/) if($line=~/^(Gm\d+)\trecent_duplication\tsyntenic_region\t(\d+)\t(\ +d+)\t.*\tID=\w+_Gm\d+\.(Gm\d+.*);median_Ks=(.*);matches=(Gm\d+:\d+\.\ +.\d+)/)

        You could clean it up quite a bit more by splitting the line on tabs and parsing each of the columns individually...