in reply to Detecting if a program or file exists

use strict; use warnings; require 5.8.7; print "Hello World!\n";

I only have 5.8.4 installed at home, and this prints:

Perl v5.8.7 required--this is only v5.8.4, stopped at math1.pl line 4.

Modify the code to require 5.8.3, and it prints:

Hello World!

Replies are listed 'Best First'.
Re^2: Detecting if a program or file exists
by FM (Acolyte) on Oct 18, 2005 at 04:29 UTC
    What about if I want to make sure a module (Win32::DirSize) is installed? And what about another program that only has one executable file?
    Thanks,
    FM
      What about if I want to make sure a module (Win32::DirSize) is installed?
      # see perldoc -f require for more info my $class = 'Win32::DirSize'; eval "require $class" or die "Couldn't load $class: $@";
      And what about another program that only has one executable file?
      my $binary = "/path/to/executable"; -x $binary or die "$binary not found";
        And what about another program that only has one executable file?
        my $binary = "/path/to/executable"; -x $binary or die "$binary not found";
        FM seems to be under Windows, since he asks about Win32::DirSize. But I guess -x is *NIX-centric and I don't know how it would behave under redmondish environments. Maybe it would just evaporate silently to -f, but I would probably use directly the latter:
        -f or die "`$_' binary not found\n" for 'C:/path/to/executable';
        You might be able to determine if a module is installed without explicitly requiring or using it by using a technique I described in Re: Case Insensitivity on Windows.
        Thanks a bunch.
        It worked as expected, however, the -x did not work and I finally use -e. How is this going to affect what I am trying to do? Thanks, FM