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 ]

paulm (5067)

paulm
  (email not shown publicly)
http://paulm.com/
Jabber: Tantrix@jabber.org

Hello! I'm Paul Makepeace [paulm.com], a regular on London.pm [pm.org]. Perl's my primary language I code in (since '95 I think); people even pay me [paulmakepeace.com] for it! Although I'd say I'm a developer I spend a substantial chunk of time being a sysadmin for my own machines (I'm also one of london.pm.org's root), all Debian boxen.

This journal is my first foray into a technical annotation of my perl life...

Journal of paulm (5067)

Monday February 14, 2005
11:22 AM

25 hours in a day

sub days_between($$) {
    (str2time($_[1])-str2time($_[0])) / SECONDS_IN_A_DAY;
}

Seems obvious enough. Then some results were non-integer. Boiled down to,

$ perl -MDate::Parse -le 'print ((str2time($ARGV[1])-str2time($ARGV[0]))/86400)' 2004-10-31  2004-11-01
1.04166666666667
$

Why? Ah, Daylight savings!

Monday January 10, 2005
11:00 PM

Binary reflex

Dave Gould says:
    6 OR 7?
paulm says:
    7
Dave Gould says:
    scuse caps lock
paulm says:
    oh, in that case I don't know

Thursday October 14, 2004
05:01 AM

Mailman fix_url.py wrapper

Mailman has this concept of a URL that's associated with a domain. Unfortunately it's not possible to configure it through the interface, which on vhosted lists is really annoying. There is an impossible-to-remember incantation with an auxilliary script. Tired of looking this up and messing up the invocation here's a wrapper. Yeah, it's in perl.

#!/usr/bin/perl

use strict;
use warnings;

# paulm, 2004-10-14
# Provide a pleasant interface to mailman's fix_url.py script
# http://www.python.org/cgi-bin/faqw-mm.py?req=show&file=faq04.029.htp

my ($program) = $0 =~ m~.*/(.+)$~;
sub usage { die "$program: $program list\@example.com\n@_.\n" }
usage("Missing list address")
        unless @ARGV == 1;
my ($local_part, $domain) = split '@', $ARGV[0];
usage ("Couldn't parse $ARGV[0] into a list address")
        unless $local_part and $domain;
print "Fixing ${local_part}\@$domain...\n";
system qq{/usr/lib/mailman/bin/withlist -l -r fix_url $local_part -u $domain};

Friday June 11, 2004
10:12 AM

Windows NT, VMS?

(Lifted from London.pm, this thread on Windows NT v. VMS).

Je 2004-06-11 00:20:29 +0100, Phil Lanch skribis:
> On Wed, Jun 09, 2004 at 02:50:35PM +0100, David Cantrell wrote:
> > I would be *much* happier running the bastard child of VMS
>
> hang on a minute ... isn't Windows NT the bastard child of VMS?
 
$ perl -pe 's/(.)/chr -1+ord $1/ge'
WNT
VMS
$
 
Apparently.
 
P

Try "IBM" too :-)

Tuesday June 08, 2004
07:32 PM

Stripping certain requests from log files

I have this service that performs a HEAD request on a few sites I run, every few minutes. The problem is that it inflates my page hit count. Being one of those problems that is too annoying to do properly, the following one-liner (line broken for a shot at clarity) came out surprisingly easily,

for i in www.paulm.com-access.log.*gz; do
  gunzip $i; f=`echo $i | perl -pe 's/.gz//'`;
  perl -ni -e 'print unless /^ftp.itransact/' $f;
  gzip $f& echo $f;
done

Friday May 28, 2004
09:36 AM

mac2unix

A "zero script" hack (-e0) to convert in-place Macs' default line endings of \r to \n.

perl -le0 -015pi mac_file.txt

The order of the -l and -0 is important. -l assigns $\=$/ (output record sep = input record sep) and then the -015 sets input record separator to octal 15, aka dec 13 aka \r. So it's splitting the input on \r and outputting (via -p) with \n.

(I was puzzled for a while trying to squeeze even more characters out of it by wondering why -l0 was behaving differently to -l -0. -l takes a number too! So the 0 was a number not a command option.)

Can any more chars be shaved off?

Saturday May 22, 2004
12:36 PM

First post!

I've recently really enjoyed reading the journals on use Perl (in particular Matts's and davorg's I'm sure I'll discover more!) and combined with a feeling I ought to spend time documenting what I get up to with perlif only so I remember in a week's timeit seemed a natural step to join up.

If you know me (heck, even if you don't :) please do say hi! Any use Perl tips gratefully received too (an overwhelming number of cool-looking doodads here...).