Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   hash of hash of hash of hash in c++ (http://www.velocityreviews.com/forums/t805766-hash-of-hash-of-hash-of-hash-in-c.html)

rp 11-10-2011 07:12 AM

hash of hash of hash of hash in c++
 
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;
}
}

red floyd 11-10-2011 04:45 PM

Re: hash of hash of hash of hash in c++
 
On 11/9/2011 11:12 PM, rp wrote:
> Hello,
> is it possible to write the below Perl code in C++ ?

Yes.



All times are GMT. The time now is 07:03 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.