#!/usr/bin/perl use strict; my $file = shift || die "USAGE: $0 filename [ max_number_to_show ]"; my $most = shift || 0; open(F, "< $file"); die "Error opening $file: $!, stopped" if $?; my @lines = map { /^\s*(".*"),?/ ? $1 : () } (<F>); close(F); # First line is xy-size, numcolors and char-width my ($x, $y, $num, $wc) = shift(@lines) =~ /(\d+)\s+(\d+)\s+(\d+)\s+(\d ++)/; die "$file: data line malformed, stopped" unless ($x && $y && $num && +$wc); my %colors; # Build color table for my $i (1 .. $num) { die "$file: color spec line #$i malformed, stopped" unless (shift(@lines) =~ /^"(.).*c\s+(\S+)/i); $colors{$1} = $2; } my (%color_count, $color, @line); for my $line (1 .. $y) { die "$file: Data line #$line malformed, stopped" unless ($lines[$line - 1] =~ /^"(.*)"$/ && (length($1) == $x*$ +wc)); @line = split(//, $1); while (length($color = join('', splice(@line, 0, $wc))) == $wc) { $color_count{$color}++; } } my @sorted = sort { $color_count{$b} <=> $color_count{$a} } keys %colo +r_count; # If specified, show only $most values @sorted = splice(@sorted, 0, $most) if $most; print "Color Frequency\n"; for (@sorted) { printf("%-20s %d\n", ($colors{$_} =~ /none/i ? 'None (transparent)' : $colors{$_ +}), $color_count{$_}); } exit;

In reply to XPM (X Pixmap) stats by rjray

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.