Perl: Matching apparently plain space in HTML with regular expression

I’ve been using a plain space character in Perl regular expressions since ages, and it has always worked. Something like this for finding double spaces: my @doubles = ($t =~ / {2,}/g); or for emphasis on the space character, equivalently: my @doubles = ($t =~ /[ ]{2,}/g); but then I began processing HTML representation from [...]

Systemd services as cronjobs: No process runs away

But why? Cronjobs typically consists of a single utility which we’re pretty confident about. Even if it takes quite some time to complete (updatedb, for example), there’s always a simple story, a single task to complete with a known beginning and end. If the task involves a shell script that calls a few utilities, that [...]

Perl + DBI: Measuring the time of database queries

It’s often desired to know how much wall clock time the SQL queries take. As with Perl, there’s more than one way to do it. This is a simple way, which involves overriding DBI’s execute() method, so it measures the time and issues a warn() with basic caller info and the time in milliseconds. The [...]

Decoding email’s quoted-printable with Perl

To make it short, the command at shell prompt is $ perl -MMIME::QuotedPrint -e ‘local $/; $x=<>; print decode_qp($x)’ < quoted.txt > unquoted.html and I needed this to extract an HTML segment of an email.

Pretty-printing data structures with Perl with Data::Dumper

As Perl allows for complicated data structures by virtue of references to hashes and arrays, it’s often useful to look into what’s going on there. In my case, it was on the output of a large JSON parse. So to make a long story short, if $tree is a reference to the data structure, go [...]

Perl + Linux: Properly cleaning up a forking script after it exits

Leave no leftover childred One of the really tricky things about a Perl script that forks this way or another, is how to make sure that the children vanish after the parent has exited. This is an issue both if the children were created with a fork() call, or with a safe pipe, as with [...]

Perl, DBI and MySQL wrongly reads zeros from database

TL;DR: SELECT queries in Perl for numerical columns suddenly turned to zeros after a software upgrade. This is a really peculiar problem I had after my web hosting provider upgraded some database related software on the server: Numbers that were read with SELECT queries from the database were suddenly all zeros. Spoiler: It’s about running [...]

Using perl for in-place search-and-replace

To make a long story short: $ perl -pi.bak -e ‘s/this/that/g’ `find inhere/ -type f` This will create backup files. Yes, you want them. Really. Otherwise, in particular under Windows, errors like this may show up: Can’t do inplace edit on inhere/example.c: Permission denied. This may look harmless, but in fact the target file ends [...]

fork(), wait(), timeout and the return codes in Perl

The mission What I really needed was a proper timeout for a certain chunk of Perl code. There is alarm() of course, but one has to watch out with certain commands that cancel it (sleep() and other less expected functions). The script also uses “system()” to run processes outside the native Perl domain, so getting [...]

A perl script sending mails for testing a mail server

Just set up your mail server? Congratulations! Now you should test it. In particular, check if it relays mails to other servers and if the response time is reasonable. Here’s a script for doing the testing. Just edit the arguments to send_mail() to match your setting. #!/usr/bin/perl use warnings; use strict; use Net::SMTP; send_mail(’′, # [...]