in reply to Re: Nested Data Structure Help
in thread Nested Data Structure Help

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.

Replies are listed 'Best First'.
Re: Nested Data Structure Help
by Abigail-II (Bishop) on Jun 13, 2002 at 13:26 UTC
    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.

        You are printing @_, but the loop variable is $_.

        Abigail