// Internet Duct Tape

Doing it Better – Avoiding backticking `pwd`, `find .`, and `mkdir -p` in Perl

Posted in Asides, Perl, Technology by engtech on May 28, 2006

When writing perl scripts, it can seem very natural to incorporate shell commands using backticks. Unfortunately, this is almost always the wrong thing to do because you are introducing a dependency on an external program without adding any of the necessary logic that might be required for portability. This isn't a very big issue for a one-off throw-away script, but in a work environment, scripts have a bad habit of being extended and reused well past your initial intentions.

This article covers some basics:

Get current working dir/Avoiding `pwd` – use Cwd
Get all of the files/subdirs in the current dir/Avoiding `find .` – use File::Find
Creating a new subdirectory / Avoiding `mkdir -p` – use File::Path

Perl – Doing it Better – Avoiding backticking `pwd`, `find .`, and `mkdir -p`

Comments Off on Doing it Better – Avoiding backticking `pwd`, `find .`, and `mkdir -p` in Perl

%d bloggers like this: