Stories
Slash Boxes
Comments
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 ]

stvn_skuo (5628)

Journal of stvn_skuo (5628)

Monday October 24, 2005
11:58 PM

Nevermind


I think the xml files that were there in blib came from my having used EUMM earlier.

Note to self: Already run realclean when switching from ExtUtils::MakeMaker to Module::Build.
03:54 PM

Module::Build weirdness


I would have sworn that Module::Build had been doing "the right thing" all along.

Given

lib/Foo/foo.PL

and

PL_files => {
   'lib/Foo/foo.PL' => 'lib/Foo/foo.xml',
}

I saw it copy foo.xml into the blib directory, etc.

I added one more item to PL_files, re-ran Build.PL, re-ran my tests, and all of a sudden the xml files were no longer being copied into blib thus causing tests to fail.

No worries as all was well again after I added

$builder->add_build_element('xml');

Tuesday September 06, 2005
11:33 PM

MREs -- now with steroids...



Years ago, after graduating from high school, I considered joining the Marines as a means of getting a college education.    I went to the recruiting office and took the "written test" and was scheduled to take a physical exam weeks later.    The timely arrival of a college acceptance letter with an offer of a scholarship diverted me away from the military.

Thinking back, I doubt I would have made it through boot camp.    I was fit and trim from having been on the swim team but I never did have the physique for any "real combat".

At the Tomb of the Unknown Soldier in Arlington National Cemetery, when I visited there on vacation, I saw The. Biggest. Guard. Ever.    He had a shaved head, crisp uniform, big stompy boots -- except that he barely made any sound as he patrolled back and forth -- and precise turns made while carrying a rifle.    Not the rat-tat-tat automatic weapon kind of rifle -- the kind with bolt-action that makes a satisfying click-click sound (or so I imagine from seeing countless action movies, as I've never fired a gun).

What brought this to mind was seeing the funeral procession of William Rehnquist, the late Supreme Court Justice, on television this morning.   His pall bearers were his former clerks. I'm not saying all his clerks eventually found desk jobs where their daily routine now involve lifting items no heavier than a briefcase -- I'll just say that they seem a bit strained while transporting the casket.   Contrast that to the funeral of Ronald Reagan, the 40th President, whose coffin was carried, seemingly effortlessly, by marching military guards.

Either the recruiters for the armed forces have a great screening process to pick out the biggest, strongest guys, or they're putting steroids into MREs (yup, steroids).
Friday August 05, 2005
01:13 AM

Just in time

Thanks rafael.   I was just looking for a way to compare files as strings and found File::Compare a bit lacking.

Looks like someone else besides me would like an option to ignore differences in number of whitespaces.   Other options I often use with the Unix diff utility include those to
  • ignore differences between lower- and upper-case letters, and
  • expand tabs to whitespace.

I suppose I could preprocess the strings before handing them off to is_string():

use Text::Tabs;
use Test::More tests => 1;
use Test::LongString;

# Apply one or more filters.
# N.B. The order in which the filters are applied matters:

my @strings =
    map {tr/\n\r\f / /s; $_}
    map expand($_) =>
    map lc($_)     =>
    <DATA>;

is_string(
    $strings[0],
    $strings[1],
    'Actually differs by one char'
);

__DATA__
This is a test of Test::LongStrings
this    is a    test     of Test::longstring

As far as the _common_prefix_length function is concerned, perhaps using substr would be a bit faster?

     while (length($x) && length($y)) {
-       my ($x1,$x2) = $x =~ /(.)(.*)/s;
-       my ($y1,$y2) = $y =~ /(.)(.*)/s;
+        my $x1 = substr($x, 0, 1, '');
+        my $y1 = substr($y, 0, 1, '');
        if ($x1 eq $y1) {
-           $x = $x2;
-           $y = $y2;
            ++$r;
        }

Sunday February 06, 2005
10:57 AM

Superbowl Sunday

I wonder how long it'll take before the Patriots' logo appears above the "use Perl;" banner...
Saturday February 05, 2005
05:00 PM

slowly going through perlapi

Notes to self:
  • With Inline::C, arguments to variadic C functions should be processed with Inline_Stack_Item(s), instead of the functions declared in <stdarg.h>.
  • Calling Perl subroutines from C? Better start reading perlguts, perlapi, and perlcall.

I don't do any XS programming, but I do use C often enough to think learning Inline to be worthwhile and, well, fun. After my first experience with Inline, I really have to give kudos to those in /p\d+p/ who so deftly handle three disciplines (e.g, Perl, C, and XS).

My first naive attempt went something like this:

use Inline 'C';

my @integers = (4, 2, 1, 5, 6, 3);

print +choose(\&lessthan, scalar @integers, @integers);
print +choose(\&grtrthan, scalar @integers, @integers);

__DATA__
__C__

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

int lessthan (int a, int b)
{
    return (a < b) ? a : b;
}
int grtrthan (int a, int b)
{
    return (a > b) ? a : b;
}
int choose( int(*fn)(), size_t count, int first, ...)
{
    va_list arg_ptr;
    int next;
    int keep;
    va_start(arg_ptr,count);
    keep = va_arg(arg_ptr, int);
    for(--count; count > 0; --count) {
        next = va_arg(arg_ptr, int);
        keep = fn(keep, next);
    }
    return keep;
}

In retrospect, other than as a learning exercise, this wasn't an ideal test of Inline::C. There's no speed advantage over a pure perl implementation. I ended up with something that seems to be half C and half XS:

use Inline 'C';
my @integers = (4, 2, 1, 5, 6, 3);

local $\ = "\n";
print +choose(\&lessthan, @integers);
print +choose(\&grtrthan, @integers);

__DATA__
__C__

#include <stdio.h>
#include <stdlib.h>

int lessthan (int a, int b)
{
    return (a < b) ? a : b;
}
int grtrthan (int a, int b)
{
    return (a > b) ? a : b;
}
int choose(CV *fn, int first, ...)
{
    SV *next_sv;
    SV *keep_sv;
    unsigned int count;

    Inline_Stack_Vars;

    keep_sv = newSVsv(Inline_Stack_Item(1));
    for(count = 2; count < Inline_Stack_Items ; ++count)
    {
        I32 retval;
        dSP;
        ENTER;
        SAVETMPS;
        next_sv = newSVsv(Inline_Stack_Item(count));
        PUSHMARK(SP);
        XPUSHs(sv_2mortal(newSVsv(keep_sv)));
        XPUSHs(sv_2mortal(next_sv));
        PUTBACK;
        retval = call_sv((SV *)fn, G_SCALAR);
        SPAGAIN;
        if (retval != 1)
        {
            croak("Big trouble\n");
        }
        sv_setsv(keep_sv, POPs);
        FREETMPS;
        LEAVE;
    }
    Inline_Stack_Reset;
    Inline_Stack_Done;
    return (int)SvIV(keep_sv);
}

Friday January 28, 2005
02:02 AM

HARNESS_PERL

[sunnydale:~] skuo% prove -Iblib2/lib t/*.t

t/00load.....Perl lib version (v5.8.6) doesn't match executable version (v5.8.0) at /usr/local/lib/perl5/5.8.6/darwin/Config.pm line 32.
Compilation failed in require at /usr/local/lib/perl5/5.8.6/Test/Builder.pm line 18.

It's my fault for having two different versions of perl: 5.8.6 under /usr/local/bin and Apple's default perl under /usr/bin.

It turns out that $^X is set to the string 'perl' and trips up my effort at running tests. All's well after setting HARNESS_PERL in my environment to /usr/local/bin/perl.

Perhaps one of the %Config entries should replace $^X inside Test::Harness::Straps (e.g., in &_command)?