If it ain’t broke, don’t fix it – Perl on Windows

I like Windows as it works for me. Usually – it just works (TM). There is no reason to complain about Windows with those fine distributions like Strawberry Perl or ActiveState Perl. I prefer ActiveState Perl due to it’s ppm packages and the package manager. They’ve built them, tested them and hopefully everything is working as designed. As I am a Mojolicious guy I don’t need that many modules for my work, everything is built in there. I don’t need a sophisticated XML parser when I can use the basic Mojolicious XML / CSS selector stuff. As I said – it works for me (TM).

However from time to time I need to install other modules which are not available with PPM. Usually they are not available because there are broken in some sort of manner on the Windows platform. However, are they really broken or is the code buggy? You’ll decide – here is an example:

# assemble cmd parameters here
my @args = qw/-w -v -x -j/;

# run the system call
system('./<command>', @args) == 0
    or die "System command failed\n";

Even if the binary might b available on a Windows platform the command will fail. This is caused by prefixing the command call with ‘./’. This is common in the Unix world and reference something in current path (aka cwd). Windows, however, can’t make a use of this notation and will fail. Just call your command without the prefix.

If you need a certain environment – PATH or other variables, please set it inside your code. Don’t muck around with paths by hand, please. There are certain modules out there which will help you with that task: File::Spec or Path::Class. The first one is inside the Perl core distribution and is available anywhere. If you want to execute a binary in the same path (./) prefix it with the getcwd() instead (see Cwd).

 

This is not a pure pro Windows post, however, I want to raise some attention on your coding style. Don’t hardcode binary paths, don’t hardcode OS specific stuff. It’s easy to code crossplattform – if you are aware of some easy things. If you code for certain platforms it’s not the fault of the OS that your code won’t work on other platforms.