G'day shabird,
Welcome to the Monastery.
You've posted your input data twice.
Working past that, is it really double-spaced as you've shown?
The output from your 'print $line,"\n";' would have been useful for us; however, you've commented that out.
There's another bigger problem.
You said "its not printing anything".
The code you posted would have printed something like:
Global symbol "@keys" requires explicit package name ...
Execution ... aborted due to compilation errors.
For future reference, please
-
take more care when posting input data,
-
post the actual code you are running, and
-
provide us with the exact output you get (even if that's only error or warning messages).
If you had made a mistake by trying to split on non-existent colons,
you still would have got the keys but the values would have been all undef. Here's a quick example:
$ perl -e '
my $x = "MIR200B miRNA";
my %h;
my ($k, $v) = split /:/, $x;
$h{$k} = $v;
use Data::Dumper;
print Dumper(\%h);
'
$VAR1 = {
'MIR200B miRNA' => undef
};
Given there's so many question marks over the data and the code, it's difficult to advise you.
The following may be close to what you were trying achieve;
or, at least, provide some insight into how you might proceed.
#!/usr/bin/env perl
use strict;
use warnings;
my %data;
while (<DATA>) {
next if $. == 1;
chomp;
next unless length;
my ($k, $v) = split;
$data{$k} = $v;
}
# To test result
use Data::Dumper;
print "*** Hash ***\n";
print Dumper(\%data);
print "*** Keys ***\n";
print "$_\n" for keys %data;
print "*** Values ***\n";
print "$_\n" for values %data;
__DATA__
GeneName GeneType
APOL4 protein_coding
CYP2C8 protein_coding
NAALADL2 protein_coding
NANOS3 protein_coding
C20orf204 protein_coding
MIR429 miRNA
MIR200A miRNA
MIR200B miRNA
Output:
*** Hash ***
$VAR1 = {
'NANOS3' => 'protein_coding',
'C20orf204' => 'protein_coding',
'APOL4' => 'protein_coding',
'MIR429' => 'miRNA',
'NAALADL2' => 'protein_coding',
'MIR200B' => 'miRNA',
'MIR200A' => 'miRNA',
'CYP2C8' => 'protein_coding'
};
*** Keys ***
NANOS3
C20orf204
APOL4
MIR429
NAALADL2
MIR200B
MIR200A
CYP2C8
*** Values ***
protein_coding
protein_coding
protein_coding
miRNA
protein_coding
miRNA
miRNA
protein_coding
|