hash of hash of hash of hash in c++

R

rp

Hello,
is it possible to write the below Perl code in C++ ?
The code creates a hash which contains hashes of hashes of hashes
which contain a key called "count" which is incremented if it exists.
Thanks for your help.
rp


-----------------------------------------
#!/opt/local/bin/perl
use strict;
use warnings;

my %hash = ();

for (my $y = 2000; $y < 2010; ++$y) {
for (my $m = 1; $m < 12; ++$m) {
for (my $d = 1; $d < 30; ++$d) {
process(\%hash, $y, $m, $d);
}
}
}
for (my $y = 2000; $y < 2010; ++$y) {
for (my $m = 1; $m < 12; ++$m) {
for (my $d = 1; $d < 30; ++$d) {
process(\%hash, $y, $m, $d);
}
}
}
use Data::Dump qw(dump);

print dump(%hash);


sub process {
my ($hash_ref,$y,$m,$d) = @_;


if ( exists ${$hash_ref}{$y}{$m}{$d}{count} ) {
${$hash_ref}{$y}{$m}{$d}{count}++;
} else {
${$hash_ref}{$y}{$m}{$d}{count} = 0;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top