Flo Edelmann
Flo Edelmann

Reputation: 2613

Is there something like `<?php phpinfo(); ?>` in Perl?

Is there something like <?php phpinfo(); ?> in Perl?

Upvotes: 6

Views: 2493

Answers (4)

tinonetic
tinonetic

Reputation: 8036

Just to add on, dont forget to add the Perl bin path in your file.

An example script I used follows:

Make sure that the following line is the first in your file:

#!/usr/bin/perl

OR For windows, may be something like(depending on your environment):

#!C:/wamp/bin/Perl64/bin/perl.exe

Snippet:

#!/usr/bin/perl
# test.cgi by Bill Weinman [http://bw.org/]
# Copyright 1995-2008 The BearHeart Group, LLC
# Free Software: Use and distribution under the same terms as perl.

use strict;
use warnings;
use CGI;

print foreach (
    "Content-Type: text/plain\n\n",
    "BW Test version 5.0\n",
    "Copyright 1995-2008 The BearHeart Group, LLC\n\n",
    "Versions:\n=================\n",
    "perl: $]\n",
    "CGI: $CGI::VERSION\n"
);

my $q = CGI::Vars();
print "\nCGI Values:\n=================\n";
foreach my $k ( sort keys %$q ) {
    print "$k [$q->{$k}]\n";
}

print "\nEnvironment Variables:\n=================\n";
foreach my $k ( sort keys %ENV ) {
    print "$k [$ENV{$k}]\n";
}

Source: http://cgi.bw.org/cgi-t/

Upvotes: 1

brian d foy
brian d foy

Reputation: 132802

What information do you want to know? phpinfo apparently tells you almost everything:

Outputs a large amount of information about the current state of PHP. This includes information about PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License.

You can get most of that somehow in Perl, but not all from the same place.

  • The Config module, which comes with Perl, has the compilation options for the interpreter
  • The Probe::Perl might give you a better interface
  • $^V has the version of the current interpreter (see perlvar)
  • %ENV has the environment (see perlvar)
  • You can use the Devel::CheckOS module to find out about the OS
  • Unless you are using mod_perl, your Perl CGI script will probably not have direct access to HTTP headers

Upvotes: 11

Josh K
Josh K

Reputation: 28883

For clarification I have included the bash prompt symbol.

$ perl --version # This is what I would use

Upvotes: 0

cjm
cjm

Reputation: 62099

use Config qw(myconfig);

print myconfig();

prints much of the information that perl -V does. You can also get individual elements of that information through the Config module.

Upvotes: 6

Related Questions