in reply to Need tips on portable Perl programming

You give the example of df, and you are right. So avoid calling external programs as far as possible. Try and use internal Perl commands, or use modules that are portable.

$^O ($OSNAME) is a useful variable to test on those occasions when you have to. When you have to use different modules depending on the platform, see the often forgotten pragma if, for example:
use if ($^O eq 'MSWin32'), 'Win32::Process'; use if ($^O ne 'MSWin32'), 'POSIX';

Replies are listed 'Best First'.
Re^2: Need tips on portable Perl programming
by DrHyde (Prior) on Nov 20, 2009 at 11:11 UTC
    Please don't do that in the general case (it may work for whatever Win32::Process does, I don't know). Assuming that everything that isn't Windows is the same is Wrong. Use Devel::CheckOS to check for things like "is this Windows?" or "is this Unix?" or "is this VMS?" or ...
Re^2: Need tips on portable Perl programming
by newbie01.perl (Sexton) on Nov 23, 2009 at 10:48 UTC
    <o> Hi,

    I totally agree with what you said below:

    "You give the example of df, and you are right. So avoid calling external programs as far as possible. Try and use internal Perl commands, or use modules that are portable."

    Now, my next question is "Is there any such Perl module or library that allows you to run one single command but somehow "clever" enough to run either the Windows command or the UNIX command?"

    It's kinda like using alias command on UNIX to map the most command Windows/DOS command into its UNIX equivalent command. If such a module exists, then perhaps that may do the trick.

    To illustrate it further, maybe there is a Perl module where I say clearscr and then inside the Perl module, it will run cls if the OS is Windows or clear if the OS is *nix? Am I making this node more confusing?