If you can use XPM, here's a solution that doesn't require any external packages:

#!/usr/bin/perl -w use strict; # reads a 2-color XPM; outputs space for white, asterisk for black my @lines = map { tr/",//d; $_ } grep {!m{^/\*|[{}]}} <>; my ($header, @c) = splice(@lines, 0, 3); my @dims = $header =~ m{(\d+)}g; die "has too many colors or is in wrong format\n" if $dims[2] > 2 || $ +dims[3] > 1; my $text = join('', @lines); # process colormap my ($w, $b); foreach (@c) { m{^\s*(\S).*#(\S+)\s*$}; hex($2) ? $w = $1 : $b = $1 } eval "\$text =~ tr/$w$b/ */"; print $text;

And, in case the prior was too readable, here's a regex-based version of the above...

#!/usr/bin/perl -w # reads a 2-color XPM; outputs space for white, asterisk for black use strict; $/ = undef; my $text = <>; $text =~ s{^[^"]*\n}{}gm; # remove noise lines $text =~ s{^\s*"\s*([^"]*\S)\s*"\s*,\s*$}{$1}gm; # unquote others $text =~ s{^\d+\s+\d+\s+(\d+)\s+(\d+)\n # dimensions (.)\s+c\s+\#([0-9a-fA-F]+)\n # colormap 0 (.)\s+c\s+\#([0-9a-fA-F]+)\n }{}mx; # colormap 1 die "has too many colors or is in wrong format\n" if $1 > 2 || $2 > 1; my ($w, $b) = hex($4) > hex($6) ? ( $3,$5 ) : ( $5,$3 ); eval "\$text =~ tr/$w$b/ */"; print $text;
update: shortened code a bit, added second version

In reply to Re: Perl BMP -- Text by bikeNomad
in thread Perl BMP -- Text by Anonymous Monk

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.