hash of hash of hash of hash in c++

Discussion in 'C++' started by rp, Nov 10, 2011.

  1. rp

    rp Guest

    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;
    }
    }
    rp, Nov 10, 2011
    #1
    1. Advertising

  2. rp

    red floyd Guest

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

    Yes.
    red floyd, Nov 10, 2011
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Red Orchid
    Replies:
    3
    Views:
    1,038
  2. Pieter Claassen
    Replies:
    1
    Views:
    1,108
    CBFalconer
    Aug 4, 2004
  3. Bo Peng
    Replies:
    4
    Views:
    786
  4. navS
    Replies:
    3
    Views:
    504
    Ismo Salonen
    May 9, 2008
  5. Srijayanth Sridhar
    Replies:
    19
    Views:
    612
    David A. Black
    Jul 2, 2008
Loading...

Share This Page