Search This Blog

Wednesday, May 20, 2015

Can I not quote YOU? When TERM is not the same as 'TERM'

As one might expect, there are subtle differences when Perl is running on Linux versus Windows (via cygwin) even when Perl is built from the same source.

On Windows (cygwin), the lines marked with ##1## and ##2## are identical:

use warnings;

my $pid = fork;

if ($pid) {
  sleep 10;
  kill TERM => $pid; ##1##
  kill 'TERM' => $pid; ##2##
  waitpid($pid, 0);
}
else {
    sleep 10000;
    exit;
}

On Linux, only the line marked with ##2## works. Even the POD for 'kill' puts quotes around the signal names. This could be due to the modules I'm using (POE and at least 100 more). Nevertheless, let this be today's all too familiar Perl lesson. I'm just telling you what you already know:

NEVER USE BAREWORDS, even if they are uppercase. Quote 'ALL' the damn strings.
Post a Comment