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` or to delete entire lines that contain a certain substring: $ perl -pi.bak -e ‘s/^.*?RUNTIME_PARAM.(?:OUTPUT|SHARED)DIR.*?[\n\r]+//gm’ $(find . -iname \*.xci) This will create backup files. Yes, you want them. Really. Otherwise, in particular under Windows, errors like this may show up: [...]

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(’127.0.0.1′, # [...]

Perl script rectifying the encoding of a mixed UTF-8 / windows-1255 file

Suppose that some hodge-podge of scripts and template files create a single file, which has multiple encoding of Hebrew. That is, both UTF-8 and windos-1255. If the different encodings don’t appear in the same lines, the following script makes it all UTF-8: #!/usr/bin/perl use strict; use warnings; use Encode; binmode(STDOUT, “:utf8″); while (defined (my $l [...]

My script for removing trailing white spaces from files

Git has this thing about trailing white spaces in source files, for good reasons. Somehow it looks like there isn’t a widely spread utility for cleaning up a lot of files in one go. On the other hand, there are plenty of them out there, but none met my needs. So I wrote yet another [...]

Perl-only CRC32 function (without C code)

It may look like a stupid idea, since the CRC32 has been implemented in some Perl modules which can be downloaded from CPAN. But all functions I found involve an XS part, which essentially means that a compilation of C code has to take place during the installation. In other words, these modules can’t be [...]