I suggest you spend a bit more effort on naming things better (and that you use strict when it doesn't hinder you, but that's another matter). As an example, try reading the main loop in this:
#!/usr/bin/perl -w use strict; # untested; merely to prove a point use GD; use File::Spec; use constant FONT_PATH => '/full/path/to/fonts/dir/'; use constant HEIGHT => 800; use constant WIDTH => 320 use constant COL_WIDTH => 195; use constant LINE_HEIGHT => 20; use constant LEFT => 5; use constant TOP => 20; my $im = GD::Image->(WIDTH, HEIGHT); $im->colorAllocate(255,255,255); my $black = $im->colorResolve(0,0,0); my @font_name = do { opendir my($dh), FONT_PATH or die "Couldn't open ", FONT_PATH, ": $!\n"; grep { $_ ne "." and $_ ne ".." } readdir $dh; }; my $x = LEFT; my $y = TOP; for (@font_name) { if($y > HEIGHT) { $x += COL_WIDTH; $y = TOP; } my $ttf = File::Spec->catfile($fontDir, $_); $im->stringTTF($black, $tff, 12, 0, $x, $y, $_) or die "Failed trying to draw $_: $!\n"; $y += LINE_HEIGHT; } open my $fh, ">", "fonts.png" or die "Couldn't open fonts.png: $!\n"; binmode $fh; print $fh $im->png;

In your code, it's a lot less obvious what's really going on. I like to believe that the renamed variables and the constants here made it extremly clear what's going on. Also, it's easy to find what "special values" a program uses that way, and they're also easy to customize.

Also, try to use lexical filehandles wherever possible. It just makes sure you'll never accidentally step on anyone else's foot.

Of course this is just a small script and wouldn't really justify the critique, but these things become second nature and happen without thinking even when you're writing small scripts, if you've gotten into the habit. And the habit will serve you well in large projects.

Makeshifts last the longest.


In reply to Re: creating an image of all of your fonts by Aristotle
in thread creating an image of all of your fonts by AssFace

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.