Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Way to find file located in unknown place?

by Elijah (Hermit)
on Dec 10, 2003 at 04:47 UTC ( #313652=perlquestion: print w/replies, xml ) Need Help??

Elijah has asked for the wisdom of the Perl Monks concerning the following question:

This might sound weird but I need a way to search for the perl interpretor with my script. I could do a simple if statement with the -e flag to see if the executable exists but I would need to know exactly where this file is located on on every system.

Is there a way I can check and see if the system has a perl interpretor installed on it during startup? Oh and in case this does not make I am compiling my program to be a stand alone program. I plan on using it on systems that do not have perl installed on it and want to limit some of the functions if no interpretor is installed.

  • Comment on Way to find file located in unknown place?

Replies are listed 'Best First'.
Re: Way to find file located in unknown place?
by chromatic (Archbishop) on Dec 10, 2003 at 05:34 UTC

    I think you have a bootstrapping problem — it's exceedingly difficult to write a Perl program that will run if Perl isn't installed.

    If I'm just completely misunderstanding you, though, you might try the magic variable $^X, which should contain the path to the current interpreter.

      As Roger said, I still can't say I understand the problem. If you are compiling with something like PAR to generate a stand alone executable, then you won't need Perl at all. Perhaps your perl script is doing something like exec'ing Perl within itself? Perhaps that could be removed?

      This may not be related to your question, but in systems where you don't know where perl is installed, you can usually get away with using the following as the shebang:


      This will execute whatever perl is in your path. If you need to see if Perl exists or not, Roger made a good point...write a shell script to do it. /bin/sh is always going to be there on Unix-ish platforms.

        Ok well I wrote a programming environment (glorified text editor) for perl in perl. Now I am going to compile the editor but in the script I have a "check syntax" and "run script" function which as I am sure you can guess call the perl interpretor.

        Instead of just erroring when this function is called and the interpretor is not on their system I would like to be able to make sure they have a perl interpretor installed and prompt them to install it if not.

        Or maybe even not have these 2 buttons show up at all if perl is not installed on the system

        I know it sounded a little confusing, does it make since now?

        Oh and I am compiling it with the free version of perl2exe but was wondering if there was a better free one out there that does not have trial version limitations. I have tried perlcc, B::CC and I think one other and they all error. perl2exe is the only one that compiles successfully.

Re: Way to find file located in unknown place?
by Roger (Parson) on Dec 10, 2003 at 04:51 UTC
    If you are on Unix, then use /bin/which:
    ~/> /bin/which perl /usr/local/bin/perl
    But I would write a little shell wrapper that checks for the existance of Perl interpreter (instead of doing it in perl).

    If you are on Windows, then you could write a little stub that checks for the Windows REGKEY - "My Computer\HKEY_CLASSES_ROOT\Applications\perl.exe\shell\Open\command\(Default)" for the path to Perl executable.

    You can also ask the user if they have Perl installed during the installation process.

    Somehow I am puzzled why do you need to have Perl installed anyway if you decide to 'pre-compile' your Perl script(s) into a single executable. Doesn't the Perl packager you use to create standalone executables already comes with a full perl interpreter?

Re: Way to find file located in unknown place?
by SquireJames (Monk) on Dec 10, 2003 at 05:17 UTC
    If you don't want to knock something up yourself, you can always use the File::Find module from CPAN

    I've used it a couple of times in the past and it's worked pretty well. Although, I haven't tried it on Win32 systems...

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://313652]
Approved by Roger
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2023-09-26 02:47 GMT
Find Nodes?
    Voting Booth?

    No recent polls found