Perl: Double Hash for 2D Table and Reference - By Eun Bae Kim (07/26/2019, 08/20/2023)
 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  
use strict;

my %hData = ();

$hData{"EBKim"}{"start"}= 300;
$hData{"EBKim"}{"end"}  = 2300;
$hData{"EBKim"}{"start"}= 5300;
$hData{"EBKim"}{"end"}  = 7000;
$hData{"EBKim"}{"start"}= 15300;

$hData{"NKLee"}{"end"}  = 17000;
$hData{"NKLee"}{"start"}= 300;
$hData{"NKLee"}{"end"}  = 1300;
$hData{"NKLee"}{"num"}  = 20;

my $ref1 = $hData{"EBKim"};
my $ref2 = $hData{"NKLee"};
print "---------------------------------------\n";
print $ref1."\n";
print $ref2."\n";
print "---------------------------------------\n"; # Added on 08/20/2023
print $$ref1{"start"}."==\n";
print ${$ref1}{"start"}."==\n";
print $$ref1{"num"}."==\n";
print "---------------------------------------\n";

my @aKey1 = keys(%$ref1);
my @aKey2 = keys(%$ref2);
my @aKey3 = keys(%hData);


foreach my $sCurKey (@aKey1) {
	print $sCurKey."\t".$hData{$sCurKey}."\n";
}
print "---------------------------------------\n";

foreach my $sCurKey (@aKey2) {
	print $sCurKey."\t".$hData{$sCurKey}."\n";
}

print "---------------------------------------\n";
foreach my $sCurKey1 (sort(@aKey3)) {
	print $sCurKey1."\t".$hData{$sCurKey1}."\n";
	my $ref4 = $hData{$sCurKey1};
	my @aKey4 = keys(%$ref4);

	print "---\n";
	foreach my $sCurKey2 (sort(@aKey4)) {
		print $sCurKey1."\t".$sCurKey2."\t".$hData{$sCurKey1}{$sCurKey2}."\n";
	}
	print "---\n";
}