shabird has asked for the wisdom of the Perl Monks concerning the following question:
I have a file named "gene.txt", which looks like this GeneName GeneType
i have read that file in perl and assigned the values to a hash. Now i want to get the keys or values from that file as i have assigned it to hash but i am unable to get those. my point is to i want to get keys by using the keys() method but its not printing the values on the left as keys and its not printing anything i don't know why i will be very thankful if anyone could help me. Thank you in advance.APOL4 protein_coding CYP2C8 protein_coding NAALADL2 protein_coding NANOS3 protein_coding C20orf204 protein_coding MIR429 miRNA MIR200A miRNA MIR200B miRNA I have a file named "gene.txt", which looks like this GeneName GeneType APOL4 protein_coding CYP2C8 protein_coding NAALADL2 protein_coding NANOS3 protein_coding C20orf204 protein_coding MIR429 miRNA MIR200A miRNA MIR200B miRNA
#!/usr/bin/perl -w use strict; open FILE1, "/Desktop/gene.txt" or die; my %hash; while (my $line=<FILE1>) { chomp $line; # print $line,"\n"; (my $word1,my $word2) = split /:/, $line; $hash{$word1} = $word2; } # Print hash for testinf purposes while ( my ($k,$v) = each %hash ) { # print "Key $k $v\n"; @keys = keys(%hash); print @keys; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getiing keys or values of a file based hash
by Fletch (Bishop) on Feb 27, 2020 at 18:34 UTC | |
|
Re: Getiing keys or values of a file based hash
by kcott (Archbishop) on Feb 28, 2020 at 07:50 UTC | |
|
Re: Getiing keys or values of a file based hash
by zubenel0 (Sexton) on Feb 27, 2020 at 18:51 UTC | |
|
Re: Getting keys or values of a file based hash
by Eily (Monsignor) on Feb 28, 2020 at 16:55 UTC | |
by choroba (Cardinal) on Feb 28, 2020 at 17:18 UTC |