Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Detecting if a program or file exists

by mattk (Pilgrim)
on Oct 18, 2005 at 05:19 UTC ( [id://500882]=note: print w/replies, xml ) Need Help??


in reply to Re^2: 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?
# 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";

Replies are listed 'Best First'.
Re^4: Detecting if a program or file exists
by blazar (Canon) on Oct 18, 2005 at 07:06 UTC
    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';
Re^4: Detecting if a program or file exists
by ChrisS (Monk) on Oct 18, 2005 at 13:38 UTC
    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.
Re^4: Detecting if a program or file exists
by FM (Acolyte) on Oct 18, 2005 at 18:01 UTC
    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://500882]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-20 00:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found