Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Problem of context?

by pabla23 (Novice)
on Oct 16, 2014 at 09:53 UTC ( [id://1104027]=note: print w/replies, xml ) Need Help??


in reply to Re: Problem of context?
in thread Problem of context?

Thanks! But for example:

use strict; use warnings; use Data::Dumper; open (FILE, "/Users/Pabli/Desktop/gene_association.goa_human"); open (FILE2, "/Users/Pabli/Desktop/go3.obo"); my %go_accession_hash=(); while(<FILE>) { my @array_with_all_fields=split(/\t/); if ($array_with_all_fields[2] eq "TP53"){ my $mio=$array_with_all_fields[4]; %go_accession_hash=($mio,''); } print "".Dumper(%go_accession_hash)."\n"; my @test2= keys %go_accession_hash; } while(<FILE2>){ print "".$test2[0]."\n"; } close FILE; close FILE2;

When i print the entire hash table outside from the "if", it prints only the last element (key) of the hash table for "n" times and i don't understand the reason!

Thanks for help

Paola

Replies are listed 'Best First'.
Re^3: Problem of context?
by choroba (Cardinal) on Oct 16, 2014 at 09:55 UTC
    You are overwriting the hash in each step:
    %go_accession_hash=($mio,'');

    To set a single key-value pair, use the following syntax:

    $go_accession_hash{$mio} = '';
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^3: Problem of context?
by biohisham (Priest) on Oct 16, 2014 at 13:44 UTC

    Are all the entries in the fifth column of my $mio=$array_with_all_fields[4] unique ?

    If the answer is "yes" then your hash can be re-written as has been suggested to you (i.e.  %go_accession_hash{$mio}=' ';). If the answer is "no" then you might want to consider using an advanced data structure that is more appropriate to capture each variation associated with $mio.

    In order to help you understand the problem and solution better It will be more useful to actually show a representative example of how your data look like and what you want to achieve from reading it in.


    A 4 year old monk
      Thanks so so so much for your help! The situation is complicated and i'm new in "Perl"! Then: if i print "array_with_all_fields4" this is my output:

      GO:0000060 GO:0000122 GO:0000979 GO:0001077 GO:0001701 GO:0001756 GO:0001836 GO:0002309 .....

      After i store this output into "mio" for a particular need. After i store "mio" into an hash table as the keys of the hash table. If i print the hash table this is the output:

      $VAR1 = 'GO:0000060'; $VAR2 = ''; $VAR1 = 'GO:0000122'; $VAR2 = ''; $VAR1 = 'GO:0000979'; $VAR2 = ''; $VAR1 = 'GO:0001077'; $VAR2 = ''; $VAR1 = 'GO:0001701'; $VAR2 = ''; .....

      the final step for me is to store keys into an array "test2" and after use this array in another "while" and in another "FILE2".

      I know that is so difficult to explain but if you want i can write to you from my personal mail!

      Thaks a lot Paola
Re^3: Problem of context?
by Anonymous Monk on Oct 16, 2014 at 21:35 UTC
    you're not checking for errors :) autodie

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1104027]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2025-11-12 05:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (68 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.