Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-25 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found