in reply to Nested Data Structure Help

I think the data structure your looking for is:
%hash = ( 'class_name' => { 'list_of_successful_jobIDs' => [ qw(foo bar) ], 'list_of_failed_jobIDs' => [ qw(val1 val2) ], }, );
To print out the 2nd element of list_of_successful_jobIDs of class_name you would use the following: print $hash{class_name}{list_of_successful_jobIDs}[1]; Good luck!

~~rob
____________________________________________________________
eval pack "h*", "072796e647022245d445f475454494c5e622b3";

Replies are listed 'Best First'.
Re: Re: Nested Data Structure Help
by Anonymous Monk on Jun 13, 2002 at 12:59 UTC
    Right. But doing this from within a foreach loop is where things are getting fuzzy. The following doesn't work:
    foreach my $class (sort keys %jobsClassKey) { my $jobid = $jobsClassKey{$class}->{jobid}; my $status = $jobsClassKey{$class}->{status}; $masterClassHash{$class}{'successfuljobs'},$jobid if ($status == 0); $masterClassHash{$class}{'partiallysuccessful'},$jobid if ($status == +1); $masterClassHash{$class}{'failedjobs'}, $jobid if (($status > 1) && ( +$status != 150)); #Termination requested by admin } print $masterClassHash{$class}{successfuljobs}[1]

    What I need to do is:

    for every class, divide jobids by fail, partially fail, and succeed.

      Do you mean something like:
      foreach my $class (sort keys %jobsClassKey) { my ($jobid, $status) = @{$jobsClassKey {$class}} {'jobid', 'st +atus'}; my $key = $status == 0 ? 'successfuljobs' : $status == 1 ? 'partiallysuccessful' : $status == 150 ? next : $status > 1 ? 'failedjobs' : next; push @{$masterClassHash {$class} {$key}} => $jobid; }

      Abigail

        Almost. Or, I'm doing somthing wrong. Here's what I'm doing to test the contents of each of the arrays:
        foreach my $key1 ( keys %masterClassHash ) { print "The class is $key1\n"; foreach my $key2(keys %{$masterClassHash{$key1}}) { print "\tstatus = $key2\n"; foreach (@{$masterClassHash{$key1}{$key2}}) { print "\t\tjobids = @_\n"; } } }

        This only yields one jobid per array, when multiple definitely exist.

        Thanks, everyone, for your help.