Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: path to perl interpreter

by kprasanna_79 (Hermit)
on Sep 29, 2005 at 06:33 UTC ( [id://495998]=note: print w/replies, xml ) Need Help??


in reply to path to perl interpreter

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

#!/usr/bin/perl

Run the program like this.

./pgm

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

-Prasanna.K

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

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

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

    And see the results:

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

    And later, to another OS:

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

      $\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print
    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-03-19 14:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found