Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

nkuitse (193)

  (email not shown publicly)

Journal of nkuitse (193)

Thursday December 16, 2004
01:52 PM

xor virgin no more

There's a rosy glow in my cheeks as I write this, for today I am an xor virgin no more.

That's right; I've just used Perl's xor operator for the first time, and it was a thrill!

The story of hoy

hoy (hack on yaml) is a script I wrote that lets me manipulate YAML documents from the command line. I can do things like create hashes and arrays:

$ hoy array </dev/null
--- #YAML:1.0 []

$ echo -e "name Yolanda P. Ipswich\nage 3" | hoy hash
--- #YAML:1.0
age: 3
name: Yolanda P. Ipswich

Fetch values from a YAML hash:

$ hoy get -p name -i ulysses.yaml
Ulysses K. Fishwick

...and so on. Each action is specified as a subcommand: hoy array ..., hoy foreach ..., etc.

hoy is very handy for what I do, and I love to say hoy. (hoy! hoy! hoy!)

The deed itself

While making a few changes in hoy today, I realized that after reading options from the command line, subcommands that don't take any non-option arguments were ignoring extra, unused arguments. That's not good, so I added a hash %takes_arguments:

my %takes_arguments = (
    'foreach' => 1,

Then I added some code right after a call to GetOptions(...) that checks for argument "overflow":

exit usage()
    if $takes_arguments{$cmd} and not scalar(@ARGV);

Then I realized I might as well check for argument "underflow" at the same time, and that's when it happened: the xor revelation (*blush*):

exit usage()
    if $takes_arguments{$cmd} xor scalar(@ARGV);


It took me a while to realize I should use xor; I first changed it to this:

exit usage()
    if ($takes_arguments{$cmd} != 0) eq (scalar(@ARGV) != 0);

Only then did I realize I was on the cusp of something new and amazing. And now, things will never be the same...

Friday August 27, 2004
05:10 PM

Pleasantly surprised

Here I am catching up on reading journals having just gotten broadband access once again after 3+ weeks without, when I run across this. Hmm, I think, why does that sound familiar?

Oh, now I remember! :-) It sure is nice when you stumble upon kind words about your own code!

Wednesday May 26, 2004
03:46 PM

Coding frenzy

Lately I've really been coding to beat the band. Mostly command-line utilities written in Perl, plus a shell script here and there.

For example:

  • pprom - write and use portable shell prompts (coming soon)
  • mac2unix - convert line endings in a file or filter stdin
  • aftermath - run a command and show what files are changed, added, or deleted
  • hoy - Hack On Yaml from the command line
  • ok and is - shell functions for testing shell scripts
  • cvsmigrate - munge CVS files in sandbox to point to a different repository
  • manpdf - view man pages as PDF (Mac OS X only at this point, but that should be easy to remedy)

aftermath will come in handy when I want to quickly see which files are being changed, added, or removed by my project Makefiles. For example, the output to the command aftermath --command 'rm foo; mkdir bar/baz' might look like this:

A bar/baz
D foo

Plus I've already started using it with ok and is to test shell scripts:

--------------------- t/ ---------------------
is $(aftermath 'myscript --foo') $(cat foo
is $(aftermath 'myscript --bar') $(cat bar
is $(aftermath 'myscript --baz') $(cat test1.baz) baz
----------------------- output -----------------------
ok 1 - foo
ok 2 - bar
ok 3 - baz

It turned out to be surprisingly easy to write - the key was to get the right incantation of diff.

This recent flurry of coding is obviously connected to the fact that my girlfriend is out of the country for seven weeks, and I don't have much of anything better to do.

My only worry is, how much longer can I keep going at this rate?

(My only other worry is, how long can I go without washing the dishes?) :-)

Thursday April 29, 2004
02:01 PM

Debugging *hurts*

So my new distribution, Time-AutoRes, just failed a cpansmoke test:

Can't locate object method "export_to_level" via package "Time::HiRes" at /root/.cpanplus/5.8.0/build/Time-AutoRes-0.02/blib/lib/Time/ line 24.

The current version of Time::HiRes inherits this method from Exporter, so it would seem that I just need to change use Time::HiRes to use Time::HiRes m.n where m.n is the earliest version in which Time::HiRes inherited from Exporter.

Unfortunately, Time::HiRes has apparently always inherited from Exporter. And upon checking the test file in question (note to self: always a good first step), I see that the failing test relies on Time::HiRes not being found -- it uses Test::Without::Module to mimic a situation in which Time::HiRes is not installed. (That's the whole purpose of Time::AutoRes -- provide access to Time::HiRes::sleep et al. when Time::HiRes is available, and fall back to CORE::sleep et al. when it's not.)

So is the bug in Test::Without::Module, Time::AutoRes, Time::HiRes, or what? I'm confused!

Here's the relevant code from Time::AutoRes:

package Time::AutoRes;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $use_hires);
$VERSION = 0.02;
@ISA = qw(Exporter);
require Exporter;
    eval 'require Time::HiRes';
    $use_hires = not $@;
    if ($use_hires) {
        @EXPORT    = @Time::HiRes::EXPORT;
        @EXPORT_OK = @Time::HiRes::EXPORT_OK;
    } else {
        @EXPORT    = qw();
        @EXPORT_OK = qw(sleep alarm usleep ualarm time);
sub import {
    if ($use_hires) {
        Time::HiRes->export_to_level(0, @Time::HiRes::EXPORT_OK);
        Time::HiRes->export_to_level(1, @_);
    } else {

How in the world do I approach fixing this when the test passes on my system (Perl 5.6.0 on Mac OS X)? Levels within levels... My brain hurts!

Sunday April 11, 2004
09:12 PM

lof (don't laugh!)

The C program I wrote about the other day has been released: source tarball and README. It's called lof and it's dead simple to use. Probably not of much use to anyone else but it scratched an itch of mine.

XP to-do list: Release early? Check. Release often? We'll see...

Saturday April 10, 2004
10:11 AM

C smells down in the cellar

(As in, C smells musty and familiar, like a basement full of old books long forgotten and now rediscovered.)

So I'm writing a simple C program to spit out the byte offsets of the lines in a file (or stdin). I'd forgotten just how much I like coding close to the machine. Well, closer than Perl anyhow. Pointers! Ah, how I love them...

Though I discovered (as expected) that my C is rusty, I was happy to find that my experience with Perl helps my C: I feel I'm coding smarter than I did before. (I found this to be true when I started shell scripting, too.)

I do feel the lack of namespaces, however. (And no, although the OOP principles I learned from C++ were helpful, there's no love there like what I feel for Perl or C.)

Hmm... what's next: back to M68K assembly language? I have fond memories but would sorely miss TMON, the lovely assembly-level debugger I used back in the day. I wish PowerPC assembler was nicer. And simpler. Sigh.

Thursday April 08, 2004
03:25 PM

Harmless drudgery

I don't know if anyone's interested, but I've released a new version of my English word list:

It's small, sleek, and the cause of much typing and eye strain for yours truly.


Number of entries: 50,000

Number of entries that I've checked: 50,000

Number of entries added since the last release: ca. 11,000

Number of part-of-speech indications: 50,000

Number of definitions: 0

Number of proper nouns: 0

How I add entries:

$ frop add 'kerfuffle (n)'
$ cat new-words | frop add
$ frop review
** Press 'y' to add a word, 'n' to reject it, or space to skip it **
$ frop commit

Resources I use to discover words and decide what to add:

  • Project Gutenberg
  • /usr/share/dict/web2
  • dict
  • google
  • Random House Webster's Unabridged Dictionary (2nd ed.)
  • The American Heritage Dictionary of the English Language (2nd ed.)
  • The Compact Oxford English Dictionary
  • My poor overtaxed brain

To make a long story short: Lexicography is hard work (and FRELI's only a word list, not a dictionary).

Thursday March 25, 2004
10:35 AM

Please release me

I have three Perl modules just begging to be released:

Plus a new version of FRELI, my English wordlist.

But somehow I just can't seem to let them go. I find myself racking my brains to think of every little detail:

  • Do I have everything in my MANIFEST?
  • Are my tests OK?
  • Did I remember to add a SEE ALSO section to that module's POD?
  • Don't forget to cvs tag!!

With tools like make distcheck, t/pod.t, and cpan-upload there's really no reason to worry. But for some reason I do anyhow.

It's like I'm a parent whose child is getting ready to leave home and go to college. All for a few little bits of code and data. Sheesh! So pathetic...

It's hard to let go.

Friday March 12, 2004
11:20 AM

New module released. Bugs found. Argh!

Hash::AsObject is now available from CPAN.

$h = Hash::AsObject->new(%myhash);
print $h->foo;  # 123

It's all implemented in AUTOLOAD so there are absolutely no verboten keys. All is permitted - even new, AUTOLOAD, and DESTROY may be used as accessors/mutators.

Oops. Dang. My tests weren't checking for VERSION, can, import, and isa. (*Sigh*). And I always wondered why I kept seeing people uploading two or more versions of the same distribution on the same day...

Thursday January 08, 2004
03:38 PM

They can pry my G4 from my cold, dead hands

My employer is replacing a bunch of Macs because of an important new Windows-only piece of software. Apparently, they didn't bother testing it using Virtual PC (if they thought of that at all) and now it's too late.

As I said, they can pry my G4 from my cold, dead hands.


Fortunately, they won't have to; I've been allowed to keep it. I'll be using Virtual PC, which I've heard (from people at other sites using the software in question) does indeed work just fine. Sadly, all the other Macs in my office will be replaced.

The funny thing is, my employer's policy is that a "replaced" computer can actually be kept on an unsupported basis. Picture a bunch of new Wintel boxes gathering dust in the corner...