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:
ump 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;
}
}
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:
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;
}
}