user6037276 user6037276 - 5 months ago 6x
Perl Question

what does "$K2ko{$D}{$C} = 1" do in perl?

cat inputfile
B <b>Overview</b>
C 01200 Carbon metabolism [PATH:ko01200]
D K00844 HK; hexokinase [EC:]
D K12407 GCK; glucokinase [EC:]


open KO,'<',"inputfile" or die $!;
my ($A,$B,$C,$D,$path_DESC,$KO_DESC);
my %K2ko; my %K2DESC; my %ko2desc;
while (<KO>) {
if (/^A<b>(.+)<\/b>/) {$A=$1;}
elsif (/^B\s+<b>(.+)<\/b>/) {$B=$1;}
elsif (/^C\s+\d+\s+(.+)\s+\[PATH:(ko\d+)\]/) {
$ko2desc{$C} = "$A\t$B\t$path_DESC";
elsif (/^D\s+(K\d+)\s+(.*)/) {
$K2ko{$D}{$C} = 1;
close KO;


Could anyone would like to tell me what does "$K2ko{$D}{$C} = 1" do in the perl script?

Thank you for any advice.


This is called a hash of hashes, which gives you a multidimensional hash. Here, "1" is the value for the above mentioned hash key.

Try to use Data::Dumper for know the structure of your data.

use Data::Dumper;
my %K2ko;
my $D = "val1";
my $C = "val2";
$K2ko{$D}{$C} = 1;
print Dumper \%K2ko;


$VAR1 = {
          'val1' => {
                      'val2' => 1