blink has asked for the wisdom of the Perl Monks concerning the following question:
The code below is part of a script which produces a CSV file. I need it to populate each field in the file, regardless of value. In other words, if a key's value is 0, I want to print "0"( that's a zero ). Here's how I populate the hash, but when I print the hash, it doesn't print the key/value pair, when the value = zero
%jobstats = ( total_jobs => 0, successful_jobs => 0, partially_successful_jobs => 0, failed_jobs => 0, jobs_started_in_window => 0, jobs_ended_in_window => 0, jobs_active_in_window => 0, retried_jobs => 0 ); %jobs = bpdbjobs($code); tie %jobstats, "Tie::IxHash"; $jobstats{total_jobs} = keys %jobs; foreach $jobid ( keys %jobs ) { my $job = $jobs{$jobid}; next if $job->{status} == 150; ++$jobstats{successful_jobs} if $job->{status} == 0; ++$jobstats{partially_successful_jobs} if $job->{status} == 1; ++$jobstats{failed_jobs} if $job->{status} > 1; ++$jobstats{jobs_started_in_window} if ( $job->{started} >= $START_SECONDS ) && ( $job->{started} <= $END_SECONDS ); ++$jobstats{jobs_ended_in_window} if ( $job->{ended} >= $START_SECONDS ) && ( $job->{ended} <= $END_SECONDS ); ++$jobstats{jobs_active_in_window} if ( ( $job->{started} + $job->{duration} ) >= $START_SECONDS ) && ( ( $job->{started} + $job->{duration} ) <= $END_SECONDS ); ++$jobstats{retried_jobs} if $job->{trycount} > 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Print hash value even if it's zero
by gjb (Vicar) on Nov 18, 2002 at 20:52 UTC | |
by fglock (Vicar) on Nov 19, 2002 at 13:43 UTC | |
|
Re: Print hash value even if it's zero
by dws (Chancellor) on Nov 18, 2002 at 20:24 UTC | |
by blink (Scribe) on Nov 18, 2002 at 20:28 UTC | |
by dws (Chancellor) on Nov 18, 2002 at 20:49 UTC | |
by blink (Scribe) on Nov 18, 2002 at 22:18 UTC | |
|
Re: Print hash value even if it's zero
by metlhed_ (Beadle) on Nov 18, 2002 at 20:35 UTC |