≡ Menu

HowTo Find Out Perl Version

How do I find out Perl version by running a cgi script from a webbrowser? How do I find out Perl version from a command prompt under Windows OR Linux / UNIX OR Apple MAC OS X operating systems?

Perl is acronym for Practical Extraction and Report Language. It is a general-purpose programming language invented in 1987 by Larry Wall. Originally developed for text manipulation. Perl has become extremely popular and is now used for a wide range of tasks, including web development and interface design.

Find Perl Version From a Linux / Unix / BSD / OS X Shell Prompt

If you have access to a shell prompt (UNIX/Linux) type the following command to find out perl version:
$ perl -v
Sample outputs:

This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi(with 53 registered patches, see perl -V for more detail)
Copyright 1987-2009, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

You can also type above command under Windows / Mac OS X by opening terminal.

Find Perl Version Using a CGI Script

If your web hosting provider don't provide access to a shell, use the following perl program to find out perl version:

Short version that avoid starting a new process (see below in comments):

$command= $];
$title = "Perl Version";
print "Content-type: text/html\n\n";
print "<html><head><title>$title</title></head><body>";
print "<h1>$title</h1>\n";
print "Perl version : ".$command;

source code - version.pl (download link)

The following code provides a little bit more information:

# Available under BSD License.
# See url http://www.cyberciti.biz/faq/how-can-i-find-out-perl-version/
$command=`perl -v`;
$title = "Perl Version";
print "Content-type: text/html\n\n";
print "<html><head><title>$title</title></head><body>";
print "<h1>$title</h1>\n";
print '<pre>';
print $command;
print '</pre>';
print "</body></html>";

Sample outputs:

Find Perl Version Command / CGI-BIN Script

Find Perl Version Command / CGI-BIN Script

Upload script to your cgi-bin directory and execute script by typing url http://mydomain.com/cgi-bin/version.pl

{ 4 comments… add one }

  • Dave March 17, 2008, 12:42 pm

    It is overkill to run a whole new process to find out the version, just read about Perl’s builtin variables in PERLVAR

    In the code above change

    $command=`perl -v`;
    $command= $]

  • Tanguy January 2, 2010, 1:20 am

    Ou pour la version type v5.10.0 :
    $command = $^V;

  • Alister April 13, 2010, 11:54 pm

    Or in versions of perl > v5.6 you can use the Version object variable $^V.
    $command = sprintf “v%vd”, $^V ; # v5.8.9

  • Dodger November 9, 2015, 3:40 pm

    Please do not tell people to write crappy Perl anymore. Seriously. People write enough crappy Perl as it is.

    I mean, what’s this “$command = $]” garbage? It’s *already a variable*. You don’t need to tell people to copy it into another (badly named) variable (badly name because it’s NOT a “command”). And what’s the “$title” variable for? What makes you think you’d need a variable for something that’s used only once? Or the multiple calls to print, one per line?

    It’s bad coding habits like this that get people started writing rubbish, inefficient Perl scripts which ultimately lead to pointy-haired managers thinking Perl is inefficient and inexplicably believing that Rails scales better or that Java is a streamlined solution. CUT. IT. OUT.

    And never ever ever ever ever, no matter how innocuous it looks, ever tell people to run a CGI script that doesn’t use strict. Seriously. FFS.

    use strict;
    use CGI();
    print <<"EOF";
        Perl Version
          Perl Version

Leave a Comment

   Tagged with: , , , , , , , , ,