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

Hi,
Could any one please help me in obtaining the below using $Perl Script$


- Perl Version installed in my machine
- Perl Installed directory path (May be C:\My_Docs\Perl or C:\Perl or D:\Perl)

Thanks,
Anand V
  • Comment on Perl Version & Installed Directory Path

Replies are listed 'Best First'.
Re: Perl Version & Installed Directory Path
by kcott (Archbishop) on Nov 08, 2010 at 07:16 UTC

    perl -V from the commandline gives the version at the top of the output; directories where your modules are installed (@INC: list) at the bottom and lots of other information in between.

    -- Ken

      Thanks Ken.
Re: Perl Version & Installed Directory Path
by roc (Sexton) on Nov 08, 2010 at 07:37 UTC
    $which perl or whereis perl
Re: Perl Version & Installed Directory Path
by cdarke (Prior) on Nov 08, 2010 at 12:23 UTC
    Since you said "May be C:\My_Docs\Perl or C:\Perl or D:\Perl" then I will assume you are running on Windows.

    The problem is that you might have more than one version installed, but Windows has a fundamental problem with that. When you type perl on the command-line (cmd.exe) it attempts to load perl.exe usings its executatble search mechanism, which is complex, but usually involves the %PATH% environment variable (use the path cmd.exe command to check).

    However, when you run a perl script from the command-line, the shell uses the file association in the registry. You can check this, for example:
    C:\>assoc .pl .pl=Perl C:\>ftype Perl Perl="C:\Perl\bin\perl.exe" "%1" %*
    In theory the %PATH% and file association might refer to different versions.
    You mentioned "$Perl Script$": I'm not sure what that is but it could be the ftype? If so, make sure you enclose it in double quotes to find the location.
Re: Perl Version & Installed Directory Path
by Hugmeir (Sexton) on Nov 08, 2010 at 20:38 UTC
    While I can't vouch for its portability, this worked for me on WinXP's cmd.exe.. And, like the OP kind of asked, it's done using Perl :)

    perl -E "say 'Path: ', $^X; say 'Version: ', $^V"

Re: Perl Version & Installed Directory Path
by Khen1950fx (Canon) on Nov 09, 2010 at 14:13 UTC
    Just to be different: This will give you the installed perl version and the path of the installed perl.
    #!/usr/bin/perl use strict; use warnings; use File::Spec; use SVN::Notify; my $exe_name = 'perl'; my $exe = SVN::Notify->find_exe($exe_name); print "Perl $]\n"; print "$exe\n";