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

Hi

Lets assume I have two perl binaries which can run my script (perla, perlb which represent two versions of perl). Is there a way to determine which perl was used to run the script from inside the script? I know that $0 gives the script name but how do I get the binary that is running the script?

Thanks

Replies are listed 'Best First'.
Re: get binary executing my script
by thundergnat (Deacon) on Mar 16, 2012 at 18:40 UTC

    How about $^X?

    perl -e" print $^X "

    yields

    C:\Perl\bin\perl.exe

    On Windows. (obviously)

      that worked, thank you so much
Re: get binary executing my script
by Marshall (Canon) on Mar 16, 2012 at 17:31 UTC
    Will the special Perl variable $] do what you want?
    $] The first part of the string printed out when you say perl -v. It can be used to determine at the beginning of a script whether the Perl interpreter executing the script is in the right range of versions. If used in a numeric context, $] returns version + patchlevel /1000.
      Hi

      thanks for the reply, no it doesn't do exactly what I want to do. it gives me the version info but the versions of perla and perlb are the same

      thanks