in reply to Re: Re: Print hash value even if it's zero
in thread Print hash value even if it's zero

I don't see what this code isn't printing 0 (zero), but I do note that print_hash_cvs is printing values in essentially random order. Hashes don't guarantee key order. Most of the time, if you set up a hash the way you do, you'll get back keys in the same order, but it's not a good idea to assume that. If some other script is going to assume field order, then you're much better off being explicit about which fields you're writing.

Something like:

my @fields = qw(total_jobs ... retried_jobs); ... foreach my $key ( @fields ) { my $val = $hash{$key}; print OUT "$val|"; }
is a safer.

Replies are listed 'Best First'.
Re: Re: Re: Re: Print hash value even if it's zero
by blink (Scribe) on Nov 18, 2002 at 22:18 UTC
    I'm using "Tie::IxHash", which will allow me to retrieve hash elements in the order of insertion.

    See Camel: pg. 139