rsennat has asked for the wisdom of the Perl Monks concerning the following question:

hi all,
i am generating an hash like this,
push @{$hoh{$component}->{$cmd}->{$testcase} }, { testsuite_type => $testsuite_type, platform_type => $platform_type, view => $view_type }
How do i maintain uniqueness for "$testcase" in the hash while generating this hash??

thanks
rsennat

Replies are listed 'Best First'.
Re: unique data in dynamic hash
by duff (Parson) on Nov 15, 2005 at 22:38 UTC

    Um ... you don't, perl does that for you. Hash keys, by definition, are unique.

Re: unique data in dynamic hash
by Roy Johnson (Monsignor) on Nov 15, 2005 at 22:38 UTC
Re: unique data in dynamic hash
by thor (Priest) on Nov 15, 2005 at 22:39 UTC
    Unless I'm missing something, each testcase will have an array of hashes stored at that location. Each testcase will be unique with respect to that. Is this not what you want?

    thor

    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come

      Hi thor,
      right. testcase will be unique. but the array of hashes gets appended again and again.
      how to maintain uniqueness with the data in the array elements.

      also one more question here, how to push hashes to each testcase.

        Well...you are using the push function and an array. If you want only one thing to be stored at that location, you'll want something like (untested):
        $hoh{$component}{$cmd}{$testcase} = { testsuite_type => $testsuite_type, platform_type => $platform_type, view => $view_type }

        thor

        Feel the white light, the light within
        Be your own disciple, fan the sparks of will
        For all of us waiting, your kingdom will come

        Show us what you want to achieve. Something like this:

        use warnings; use strict; use Data::Dumper; my %hoh; while (<DATA>) { my @items = split ' '; push @{$hoh{'this'}->{'that'}->{'theOther'} }, [@items]; } print Dumper (\%hoh); __DATA__ eggs bacon cheese tomatoes potatoes onions beans peas cabbage

        Perl is Huffman encoded by design.
Re: unique data in dynamic hash
by dave_the_m (Monsignor) on Nov 15, 2005 at 22:43 UTC
    How do i maintain uniqueness for "$testcase" in the hash while generating this hash
    That's obvious: you need to convolve the contraint of the unique foreign key index parameter; preferably using a FFT, or failing that, using a 15mm to 1/2" compression adaptor. Alternately, you might want to reformulate your question in such a way that someone other than you has a clue what you're asking...

    Dave.

Re: unique data in dynamic hash
by GrandFather (Saint) on Nov 15, 2005 at 23:02 UTC

    Show us some code that runs (and doesn't depend on anything external to the code), the output that you see, and the output that you expect. We have seen this bacon and eggs example before and it has just as many unknowns as it did the first time around.

    We can invent stories, but sometimes our mind reading ability fails. Code speaks louder than words.


    Perl is Huffman encoded by design.