in reply to Debugging DBD::Chart

tilly's addressed your main point, but I thought I should point out two things about get_top_sources:
  1. You're never subtracting from $total when you add stuff to your return value, meaning that the "other" slice is forever too big
  2. Including the "other" slice, you actually produce $max_wedges+1 wedges
Here's what I might do, but I'm a bit odd. After you calculate @sorted...:
my @sorted = sort { $events{$b}{'count'} <=> $events{$a}{'count'} } keys %events; if (@sorted > $max_wedges) { map { $events{'other'}{'count'} += $_ } @sorted[$max_wedges..$#sorted]; @sorted[$max_wedges..$#sorted] = ('other'); } return [map { {$_ => $events{$_}{'count'}}; } @sorted];
Note that $total is now never used, so there's no longer any reason to be calculating it above.

This uses map heavily, which is sometimes a bit odd to get used to, but I find it leads me to write stuff that I can look at later and easily read. YMMV.

Replies are listed 'Best First'.
2Re: Debugging DBD::Chart
by jeffa (Bishop) on Feb 21, 2004 at 16:53 UTC
    Seems to me like the datastructure is more complex than it needs to be, but if it gets the job done, cool. :) However, there is no need to use map in void context:
    if (@sorted > $max_wedges) { $events{other}{count} += $_ for @sorted[$max_wedges..$#sorted]; @sorted[$max_wedges..$#sorted] = ('other'); # loaded gun? }

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)