I recently had occasion to try and determine the relative densities of blocks of different characters in the default font for my CLI. First I just printed out one line of each character on the screen and started to write down a list putting them in order of relative density, but this rapidly became untenable. So I set about trying to write something that would allow me to at least partially automate the process. After writing a skeleton with a couple of for loops it struck me that what I was doing was sorting the characters by a visual criteria.

Whilst I couldn't think of a simple way of having the script make the determination for me, I realised that I could use the built-in sort function to take care of the houskeeping and came up with the following script.

#! perl -slw use strict; use Term::ReadKey; sub key{ my $key; ReadMode 4; 1 while not defined( $key = ReadKey(0.1) ); ReadMode 0; return $key; } my @c = (32..127); @c = sort { system 'cls'; print chr($a) x 16, ' ', chr($b) x 16, ' ', chr($a) x 16, ' ', chr +($b) x 16 for 1 .. 8; print ''; print chr($b) x 16, ' ', chr($a) x 16, ' ', chr($b) x 16, ' ', chr +($a) x 16 for 1 .. 8; print ''; print chr($a) x 16, ' ', chr($b) x 16, ' ', chr($a) x 16, ' ', chr +($b) x 16 for 1 .. 8; print ''; print chr($b) x 16, ' ', chr($a) x 16, ' ', chr($b) x 16, ' ', chr +($a) x 16 for 1 .. 8; print ''; print 'Enter 1 if top left is darker, 2 if they are the same, 3 if + top right is darker'; key()-2; } @c; print $_, ' : ', chr() x 50 for @c;

Whilst this particular task is not likely to be needed very often, the basic idea could be used for anything that would benefit from the A/B comparison technique. Whether it's putting your favorite bands in order of preference, or deciding which college to go to. Basically anything where it's easier to make a judgement by considering 2 things at a time rather than the a whole group together.

Silly idea, but I found it useful:)


Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.


In reply to Really slow sort, but useful. by BrowserUk

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.