Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

path to perl interpreter

by rkillera (Novice)
on Sep 29, 2005 at 06:02 UTC ( #495992=perlquestion: print w/replies, xml ) Need Help??
rkillera has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone, Suppose a user runs a perl script in the following way: /home/userx/bin/perl Inside the script, how can I find the path of the perl interpreter (/home/userx/bin/perl) in order to launch another script? I hope this is clear enough

Replies are listed 'Best First'.
Re: path to perl interpreter
by rnahi (Curate) on Sep 29, 2005 at 06:06 UTC

    The variable $^X holds that information.

    $ perl -le 'print $^X' /usr/bin/perl

    See perlvar

Re: path to perl interpreter
by kprasanna_79 (Hermit) on Sep 29, 2005 at 06:33 UTC
    Hi rkillera,

    The $^X variable (in the first reply) displays the first word of the command line you used to start this program. If you started this program by entering its name, the name of the program appears in $^X. If you used the perl command to start this program, $^X contains perl.

    The following statement checks to see whether you started this program with the command perl:

    if ($^X ne "perl") { print ("You did not use the 'perl' command "); print ("to start this program.\n"); }

    So the first reply might not be so useful in your case.

    I dont know which platform Your working with. But in unix i usually do this way.

    $path = `which perl`; print $path; /usr/bin/perl

    If you want to run perl script there is also another way. Put the perl interpreter path in the first line of your program. This is called shebang ling techinically


    Run the program like this.


    This will run from the interpreter you have mentioned in the first line of the program.


      What you say does not agree to the docs and to my practice.

      $ cat #!/usr/bin/perl printf "operating system: %s\n executable: %s\n", $^O, $^X, ;

      And see the results:

      $ perl operating system: linux executable: /usr/bin/perl $ chmod +x $ ./ operating system: linux executable: /usr/bin/perl

      And later, to another OS:

      $ perl operating system: freebsd executable: /usr/local/bin/perl
        Just to add more information to it:
        $ perl
        operating system: darwin
         executable: perl
        $ /usr/bin/perl 
        operating system: darwin
         executable: /usr/bin/perl
        $ chmod +x
        $ ./ 
        operating system: darwin
         executable: perl

        Hi Mahi,

        Why cant you try it in unix machines.Any how good try with linux and freeBSD. But what i tried is with unix HP-UX B.11.11. Might be you check here if u can.

        More over i am fond of reading Perl in 21 days where this doc was described. May be you can check that and put your comments to the author of the book


        Since you are that much confident with your idea i need to give you the result what i got from your code

        perl -le 'print $^X' perl

        May be here according your code unix may performing wrongly. If so put a cc to unix group too apart from 21 days author.


        Edit planetscape - removed link to copyrighted material

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://495992]
Approved by tomazos
Front-paged by dbwiz
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2018-07-19 06:03 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (403 votes). Check out past polls.