in reply to Setting up a log to determine font size

So what is the current output? What would you like the output to be? What does DetermineFontSize return?
sub DetermineFontSize ($) { my ($tagCnt) = @_; my $cntRatio; if ($useLogCurve) { $cntRatio = (log($tagCnt) - $minLog)/$logRange; } my $fsize = $minFontSize + $fontRange * $cntRatio; return $fsize; }

So what do you expect to happen if $useLogCurve isn't set? Currently the sub will always return $minFontSize in that case (and emit a warning that $cntRatio is uninitialized).

Replies are listed 'Best First'.
Re^2: Setting up a log to determine font size
by Anonymous Monk on May 22, 2008 at 10:33 UTC
    The current output (without the sub) is that each tag is printed out but the font size is determined by the count so I end up with font sizes of 100+ pixels in places. What I'm trying to do is to output the values within the font range (currently 10 to 36).
    If I set useLogCurve to 0, then all the results are printed in out a uniformly small print size. Actually, having commented out the first foreach loop, it is outputting the results within a range 23 to 27 pixels (not surprising as the values are fairly similar) although the results are being printed right across the screen without wrapping (but that's an markup and CSS issue). Thanks.
      What you tried to do (and failed) is to calculate the minimum and maximum number of occurrences.
      foreach $word (%tag) { $maxTagCnt = $tag{word} if $tag{word} lt $maxTagCnt; $minTagCnt = $tag{word} if $tag{word} gt $minTagCnt; }
      There are two mistakes here. The first is that you iterate over all elements of %tag, not just the keys. Use foreach $word (keys %tag) {...} instead, or use each. The second mistake is that you try to compare numbers with lt and gt. Those two compare strings, but "2" gt "10" isn't what you want. Use < and > instead.

      You can make that even easier:

      use List::Util qw(min max); my $maxTagCount = max values %tag; my $minTagCount = min values %tag;