in reply to Re: Detecting if a program or file exists
in thread Detecting if a program or file exists

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
  • Comment on Re^2: Detecting if a program or file exists

Replies are listed 'Best First'.
Re^3: Detecting if a program or file exists
by mattk (Pilgrim) on Oct 18, 2005 at 05:19 UTC
    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
        FM,
        Take a look at perldoc -f -X. The difference between -e (exists) and -x (executable by effective UID/GID) may be a big one. Before I go any further - what do you mean -x didn't work? What happens when you try to run it? What's the output? What's the error message? Saying "it doesn't work" isn't very helpful.

        Cheers - L~R