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 ]

jdporter (36)

Journal of jdporter (36)

Monday July 15, 2002
11:19 AM


Here's Yet Another Bad Practice That Makes Me Wince Every Time I See It:

when people use setup as a verb, when they should write set up -- two words.

Other things are similar, but not quite as ubiquitous. E.g. "everyday", as in the ridiculous "floss your teeth everyday".

And WTF is up with "albeit"? Last Saturday was bizarre. I read like half a dozen articles (both on line and in print) in a row, and every single one used the word "albeit". The RNG in the Matrix needs a good thump, or something.

Friday July 12, 2002
05:29 AM

the golden rule ain't so...

It just occurred to me that the Golden Rule is pretty lame.

I mean, it may be great for kids, when you're trying to socialize them. But for adults, its usefulness is pretty limited.

The problem is the premise: it works if we all want the same thing. But we don't. We all want different things. So if you want to be nice to someone, don't treat them the way you would want to be treated; treat them the way they want to be treated.

This came to me as I was pondering a recent thread on an email list, in which two people expressed entirely opposite viewpoints on the issue of "courtesy copies". One person finds them annoying, and so he always trims out all addresses from To/Cc except for the email list; the other person thinks they're useful, so he leaves the other addresses in. They're both following the Golden Rule, and in the process, hurting each other. The Golden Rule has backfired.

Of course, in a situation like this, things aren't so black-and-white, since there are the other members of the list to consider. Both individuals are serving the interests of some fraction (roughly half?) of the community, so it's not like either one should necessarily be enjoined to reverse his behavior.

Wednesday July 10, 2002
10:31 AM

tcl and smalltalk

Believe it or not, reading the perl6 summaries (thanks, pd!) has gotten me to look at other "meta-compiled" languages, in particular, Tcl and Smalltalk.

I have to say, I really like the semantics of Tcl (the source-level language) (though the syntax is perhaps slightly less than ideal), and I really REALLY like the execution semantics of the smalltalk virtual machine. But the syntax of Smalltalk is heinously hideous! I wonder if there are any other languages that have back-ends targeting the smalltalk vm? I almost wish the perl6 guys had considering using the smalltalk vm, at least as a starting point. So much good work has already been done on virtual machines, and I'm not convinced that reading a few papers is enough to allow one to say that he is not reinventing the wheel.

Thursday June 27, 2002
11:34 PM


Well, I finally decided that it has been waay too long since I put a module on CPAN, so went about making one that I've been thinking about for a while.

Basically, sometimes you want to do something with one of several arrays (or hashes) based on some discriminant. For example, you have have a list of filenames, and you want to stick all the file names in one array and directory names in another. Ordinarily you might do this:

    for ( @names ) {
        if ( -d $_ ) {
            push @dirs, $_;
        } else {
            push @files, $_;

Or perhaps:

    @a = ( \@files, \@dirs );
    for ( @names ) {
        push @{ $a[ -d $_ ] }, $_;

If you think you're clever, you might do this:

    for ( @names ) {
        push @{ -d $_ ? \@dirs : \@files }, $_

But what I want is to do this:

    for ( @names ) {
        push @x, $_

and have @x be magically aliased to the correct array.

So I wrote a module which does this. It uses tie, of course.

    tie my @x, 'Tie::Multiplex',
          sub { -d $_ },
          [ \@files, \@dirs ];

Now the above form will Just Work.

The first argument after the the tie class name is a sub-ref which is called by the object to get an index value. The next argument is an array(ref) of array-refs. The result of calling the sub is used to select one of the arrays in that anonymous array. In the above example, -d returns either true or false, which get converted into numeric (0 or 1) for indexing into the array.

You could have more than two, and you could have a hash of arrays instead of an array of arrays:

    tie my @x, 'Tie::Multiplex', \$proto,
              http => \@http,
              ftp => \@ftp,
              mailto => \@mailto,

    for ( @URLs ) {
        $proto = extract_proto $_;
        push @x, $_;

There, I didn't use a sub, I just supplied a ref to the variable to be queried directly.

Also you can multiplex hashes instead of arrays:

    tie my %x, 'Tie::Multiplex',
        sub { is_word_valid $_ },
        [ \%invalid_words, \%valid_words ];

    for ( @words ) {

That way, %valid_words ends up with keys which are all the valid words.

What happens if your selector sub returns an index which is out of range?

    my @arrays = ( \@present, \@absent );
    tie my @x, 'Tie::Multiplex',
        sub { system("grep 'foo' $_")>>8 },
    # ordinarily, grep just returns 0 if found,
    # 1 if not found.

    for ( @files ) {
        push @x, $_;

    # but if the file does not exist, grep returns 2, and we don't have that many arrays to push onto.

By default, the Tie::Multiplex object will autovivify the new member. (The reason for the @arrays variable above is so that you could actually go get the newly-made sub-arrays if you're interested.)

But if you want to be strict, you ask Tie::Multiplex to barf on out-of-bounds conditions, by passing a true value as a third arg:

    tie @x, 'Tie::Multiplex', \$i, \@arrays, 'BARF';

I think it's purty sweet, but I am skeptical that anyone would want to use it.

But then, maybe I'm just not visionary enough to foresee the ends to which someone might be inspired to use such a module.

Wednesday June 26, 2002
04:49 PM

this program

Yup, I'm programming in Perl at work.

We had this nasty old perl program floating around, and when I looked into it, I could not believe the insanely bad programming. I'd like to say that the programmer was a converted Fortran hacker, but that would be too generous. I can't even assume that this programmer learned how to write perl by looking at Matt's Scripts. It's more like, he selected about 1 in 5 random lines from perltut, and kept only those bits that worked without modification. As a result, the only array operations he knows about are:

    for ( @a )

    @a = <F>;

    $a[$i] = ...

That's sure not much to go on.
He didn't even know how to assign a list to an array. He thought the way to initialize (or "blank out") an array was with

    $a[0] = "";


He also didn't know about push. In order to add an element onto an array, he would do the following:

    open F, "> file";
    for ( @a ) {
        $line = $_; # lord have mercy.
        print F "$line\n";
    print F "new item\n";
    close F;
    open F, "< file";
    @a = <F>;
    close F;

This was done in about two dozen places in this ~5000 line program. As you can imagine, it ran like a dog.

Also, this programmer knew nothing about lexical variables, subroutine arguments, or subroutine return values. All variables global; no use strict or perl -w. ;-P

(more later...)

Tuesday June 25, 2002
12:06 PM


So I've installed Mozilla 1.0 on my stupid, consarned Windows box here at work (interestingly, my company has mandated the use of Windows (NT4) and Microsoft Office crap -- "All documents shall be in Word format" -- for most things... but then, "Thou shalt not use IE, but rather, Netscape").

Well, Netscape was giving problems, acting flaky, and IE, while sufficient in a pinch, was leaving a very bad taste in my mouth. So I went searching for a Better Browser. I've tried Opera in the past, and though it has some niftiness, it's also not open source. And then I heard that Moz1.0 was out, so I tried that.


Mozilla rocks! On Windows at least, it is very slick, full featured, and stable. It also allegedly handles the latest in web standards correctly. Woo hoo!

Monday June 24, 2002
10:25 AM

Bad dream last night

Do you remember, back when the U.S. Marines were deployed in Somalia (as in Black Hawk Down), we heard stories on the news about the use of a drug in Somalia called khat, a leafy plant that is chewed.

Well, for some reason, my unconscious mind decided to make that the basis of a terrible dream last night.


Apparently some marines, or other persons deployed to Somalia, had brought back with them khat plants to the U.S.

Then, someone figured out a way to isolate and purify the active ingredient, a powerful narcotic which in its natural state is extremely dilute.

Addiction is becoming epidemic. The use of this drug is accelerating so rapidly that the legislative bodies have not had time to outlaw it.

This drug is distributed and consumed in the form of a clear, colorless syrup. It is administered orally. It is not swallowed, but is held in the mouth, to be absorbed through the mucus membranes.

The user can take one or two spoons of the syrup himself, but then quickly enters a stupor. After that, someone else administers the drug, dripping it (like honey) into the user's mouth. After just a few more spoonsful of this stuff, the addict begins to sieze. Scenes of this drug use (parties) have several people with mouths agape, clear syrup running down their chins onto their clothes, convulsing and unable to sit upright.

And yet, there appear to be (so far) no lasting detrimental effects. No known instances of death amongst the addicted population, no cases of someone emerging from their stupor with half their previous I.Q. And everyone insists that the drug produces very pleasurable feelings in the mind, and they all want to do it again, despite the rather unpleasant appearance of its consumption to others. Physical addiction is instantaneous, and psychological addition almost so.


Horrible, just horrible.

10:02 AM


Has anybody else noticed this?

On the evening news, when they're talking about some recent local crime (for example), you'll hear the idiot reporter say things like:

The suspect then smashed through this window, out into the alley; witnesses say the suspect then jumped in a car and sped away...

What's wrong here? It is not the suspect who did these things, it is the perpetrator.

People seem to have forgotten about the word "perpetrator", and consequently the critical difference between a perpetrator and a suspect.

A suspect is a person whose identity, or some other personal info, is known, and who is thought -- though not (yet) known -- to have committed the crime. The perpetrator is the person who did, in fact and in actuality, commit the crime, even if nothing about him/her is known at all. The perpetrator is the person who is truly guilty of the crime, even if never identified, caught, or tried. A suspect is someone can be identified and caught, and yet who is presumed innocent until proven otherwise in court.

Friday June 21, 2002
03:16 PM

Eggplant rulz

I've decided that eggplant is about the yummiest thing in the whole wide world. I could eat it every day. Jen sorta got me started on it, with this Persian stew (khoresh-e bademjan), but other forms are good too. Like eggplant parmesan. And bengan bharta. And baba ganoush. And imam bayildi.


(Any other names for it?)

Thursday June 20, 2002
01:55 PM


Seems like some people actually use their journals to write down what they're doing that day. I suppose I could give it a try...

I'm going for a hair cut tonight. First time in months, and man am I overdue. Jeni has decided to let me get a color this time (after years of pleading). Probly because she has a coupon for it.

Did anyone watch American Idol last night and the night before? I was very skeptical at first, because it was such an obvious rip-off of Pop Stars. (Fox copying WB. Imagine!) But it turned out not to be.

One thing that was cool was that the show was broadcast live. LOTS of unscripted moments. I can't believe how awful some of the contestants were, at this semifinal level. That girl Rhodesia... words can not describe. What the hell was she thinking, with "Daydream Believer"? Anyway, there's no way she could win, because not only must they have vocal talent, and showmanship, but they have to have The Look. That rules out a lot of people, including people with talent.

My fave: Ryan Starr. The girl can obviously sing. I bet she really could sing anything thrown at her. Also I have to give her extra marks because she looks *exactly* like one lover from the days of my youth, and also a lot like another sweetheart of not so long ago.

Jeni and I are planning to go see Norah Jones in concert tomorrow night at the 9:30 club. Now there's a girl with talent. Diana Krall WISHES she could sing half so well as Norah Jones.
    Norah Jones++
    Diana Krall--