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; }
In reply to Getiing keys or values of a file based hash by shabird
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |