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 09:47 AM.

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


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 53 54 55 56 57