For one thing your sample file has no ":" characters in it so your split isn't doing what you want; use my( $k, $v ) = split( /\s+/, $line ) instead.
$ perl -E '$_=qq{GeneName GeneType};my($foo,$bar)=split(/:/,$_);say + qq{foo: $foo\nbar: $bar}' foo: GeneName GeneType bar: $ perl -E '$_=qq{GeneName GeneType};my($foo,$bar)=split(/\s+/,$_);s +ay qq{foo: $foo\nbar: $bar}' foo: GeneName bar: GeneType
That aside, your commented out printing code should have been fine. My guess is since your split wasn't working the way you expected you went and tried to do what you've got now, which just doesn't make sense (walk over every item in the hash, and for each item print a list of all the keys in the hash). Alternately consider using Data::Dumper or YAML::XS or the like to print out the contents.
$ perl -E '%hash = qw( a b c d ); while( my( $k, $v ) = each %hash ) { + say qq{$k => $v}; }' c => d a => b
The cake is a lie.
The cake is a lie.
The cake is a lie.
In reply to Re: Getiing keys or values of a file based hash
by Fletch
in thread Getiing keys or values of a file based hash
by shabird
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |