Perl version on free host?

jdw999

New Member
Messages
44
Reaction score
0
Points
0
I posted this question in the free hosting forum, and evidently there are no Perl programmers online just now. Or something.

Anyhow, I want to write some CGI scripts in Perl on my local machine for development before I upload to the X10 server. To get my local environment set up, I would like to find out what version of Perl is installed on absolut.

CPanel used to display this info, but I don't see it--though the versions of MySQL and PHP are displayed. I can run a script that displays the server environment, but don't know enough to query for the Perl version, or even if that is possible.

I have searched the forums and don't find any way to determine the version of Perl that is running on my host. Any clues?
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
I found the query but I don't know enough about perl to run it :p

Code:
#!/usr/bin/perl
# 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 $command;

print "</body></html>";
 

jdw999

New Member
Messages
44
Reaction score
0
Points
0
Hey garrettroyce.

I copied and pasted the code you found into a blank text file and saved it as "perlv.pl" in the cgi-bin dir of the apache server on my development box. I typed: "localhost/cgi-bin/perlv.pl" into the address bar and got the same message I get when I type "perl -v" on the command line...which makes perfect sense. lol

So, I uploaded the script to my X10 cgi-bin directory and changed the permissions to 755, typed the address into the browser address window, and got a 500 error. I have several scripts that work, so it is not the path to perl, though it may be something else in the script.

Or, it could be that X10 somehow blocks certain queries. Like you, I don't know enough to make a guess on that.

For now, I am using ActivePerl (on Windows, cause ... I dunno; too much trouble to reboot to my Ubuntu partition all the time, i guess) 5.8.9 and I will see if I run into any problems.
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
Sorry I couldn't be more help :p

I know in other programming languages you can check if a function exists, so if you find a function that only exists in a bleeding-edge version of perl, you can always check to make sure our version supports it:
Code:
pseudo-code:
if function_exists("new_perl_function")  execute new_perl_function()
else print 'ERROR: Function does not exist'
 
Last edited:

jdw999

New Member
Messages
44
Reaction score
0
Points
0
Thanks garrett.

Seems I read somewhere that we don't have shell access to the X10 environment. I wonder if that is why this script does not work. In other words, whether the server reads the script as somehow equivalent to using the command line.
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
Ah, makes sense.

ok, I found this script, but I get a 500 error. Maybe you can get it to work:

Code:
#!/usr/bin/perl
print "Content-type: text/html\n\n";

#Location of Perl
$output = `whereis perl`;
@locations = split(" ",$output);
foreach $line (@locations) 
	{
	$whereperl .= "$line<br>";
	}

#Location of Sendmail
$output = `whereis sendmail`;
@locations = split(" ",$output);
foreach $line (@locations) 
	{
	$wheresendmail .= "$line<br>";
	}

#Location of Current Directory
$currentdirectory = `pwd`;

#Perl Variables
$perlversion = $];
#Perl Os
$perlos = $^O;


#Module Paths
foreach $line (@INC) 
	{
	$modulepaths .= "$line<br>";
	}

#Environment Variables
$environment = qq~
<table width="100%" border="1" cellspacing="0" cellpadding="2" bordercolor="#000000">
<tr> 
<td colspan="2" bgcolor="#0033CC"> 
<div align="center" class="tabletitle">Environment Variables</div>
</td>
</tr>
~;

@allkeys = keys(%ENV);

foreach  $key (@allkeys) 
{
$value = $ENV{$key};
if ($value eq "") {$value = "-";}
$environment .= qq~
<tr> 
<td width="150" class="tableitems">$key</td>
<td class="tablevalue">$value</td>
</tr>
~;
}
$environment .= qq~
</table>
~;


$documentroot = $ENV{'DOCUMENT_ROOT'};
if ($documentroot ne "")
{
@lines = `du -c -k $documentroot`;
$lastline = @lines-1;
($diskusage) = split/[\t| ]/,$lines[$lastline];
}

#Server Software
$serverip = $ENV{'SERVER_ADDR'};
$servername = $ENV{'SERVER_NAME'};
$serverport = $ENV{'SERVER_PORT'};

$serversoftware = $ENV{'SERVER_SOFTWARE'};

$serveruptime =`uptime`;


#Localtime
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
@months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
$date = sprintf("%02d-%s-%04d",$mday,$months[$mon],$year+1900);
$time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
$localtime = "$date, $time";

#GMTtime
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
@months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
$date = sprintf("%02d-%s-%04d",$mday,$months[$mon],$year+1900);
$time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
$gmttime = "$date, $time";


print qq~
<html>
<head>
<title>Perlonline.com - Perlinfo.cgi</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.tabletitle {  font-family: Arial, Helvetica, sans-serif; font-size: 14px; font-weight: bold; background-position: center; color: #FFFFFF}
.tableitems {  font-family: Arial, Helvetica, sans-serif; font-size: 12px}
.tablevalue {  font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: bolder}
-->
</style>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#000000">
  <tr bgcolor="#0033CC"> 
    <td colspan="2" class="tabletitle"> 
      <div align="center">Server Information</div>
    </td>
  </tr>
  <tr> 
    <td class="tableitems" width="150" valign="top">Name</td>
    <td class="tablevalue">$servername</td>
  </tr>
  <tr> 
    <td class="tableitems" width="150" valign="top">IP</td>
    <td class="tablevalue">$serverip</td>
  </tr>
  <tr> 
    <td class="tableitems" width="150" valign="top">Listing Port</td>
    <td class="tablevalue">$serverport</td>
  </tr>
  <tr> 
    <td class="tableitems" width="150" valign="top">Document Root</td>
    <td class="tablevalue">$documentroot</td>
  </tr>
  <tr>
    <td class="tableitems" width="150" valign="top">Disk Usage by Root</td>
    <td class="tablevalue">$diskusage Kb</td>
  </tr>
  <tr> 
    <td class="tableitems" width="150" valign="top">Software's Installed</td>
    <td class="tablevalue">$serversoftware</td>
  </tr>
</table>
<br>
<table width="100%" border="1" cellspacing="0" cellpadding="2" bordercolor="#000000">
  <tr bgcolor="#0033CC"> 
    <td colspan="2" class="tabletitle"> 
      <div align="center">Perl Information</div>
    </td>
  </tr>
  <tr> 
    <td class="tableitems" width="150" valign="top">Perl version</td>
    <td class="tablevalue">$perlversion</td>
  </tr>
  <tr> 
    <td class="tableitems" width="150" valign="top">Compiled For</td>
    <td class="tablevalue">$perlos</td>
  </tr>
  <tr> 
    <td class="tableitems" width="150" valign="top">Module Paths</td>
    <td class="tablevalue">$modulepaths</td>
  </tr>
</table>
<br>
<table width="100%" border="1" bordercolor="#000000" cellpadding="2" cellspacing="0">
  <tr bgcolor="#0033CC"> 
    <td colspan="2" class="tabletitle"> 
      <div align="center">Location of Important Unix Programs</div>
    </td>
  </tr>
  <tr> 
    <td class="tableitems" width="150" valign="top">Perl</td>
    <td class="tablevalue">$whereperl</td>
  </tr>
  <tr> 
    <td class="tableitems" width="150" valign="top">Sendmail</td>
    <td class="tablevalue">$wheresendmail</td>
  </tr>
</table>
<br>
<table width="100%" border="1" cellspacing="0" cellpadding="2" bordercolor="#000000">
  <tr bgcolor="#0033CC"> 
    <td colspan="2" class="tabletitle"> 
      <div align="center">Time</div>
    </td>
  </tr>
  <tr> 
    <td class="tableitems" width="150" valign="top">Server Time (Local)</td>
    <td class="tablevalue">$localtime</td>
  </tr>
  <tr> 
    <td class="tableitems" width="150" valign="top">Server Time (GMT)</td>
    <td class="tablevalue">$gmttime</td>
  </tr>
</table>
<br>
$environment 
<p align="center" class="tablevalue">&nbsp;</p>
<p align="center" class="tablevalue">All rights Reserved 2001. <a href="http://www.perlonline.biz">Perlonline.biz</a></p>
</body>
</html>
~;
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
You can also use $] or $PERL_VERSION/$^V.
Code:
#!/usr/bin/env perl
use CGI ':standard';

print header('text/plain');
printf "\$^V: v%vd\n",$^V;
print '$]: ',int($]),'.',int(($]-int($]))*1000),'.', int(($]*1000 - int($]*1000))*1000), "\n";
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
I get a server error when using that script. I don't know if it's something I'm doing or if, like all the other scripts I've tried so far, it just doesn't work here at x10.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
I get a server error when using that script. I don't know if it's something I'm doing or if, like all the other scripts I've tried so far, it just doesn't work here at x10.

It works for me on Absolut (where it reports v5.8.8). Anything interesting in your error log?

Edit:
1st script had a rounding error. Here's a fixed version:
Code:
#!/usr/bin/env perl
use CGI ':standard';

print header('text/plain');
printf "\$^V: v%vd\n",$^V;
print '$]: ',int($]),'.',int(($]-int($]))*1000),'.', int(($]*1000 - int($]*1000))*1000 + 0.5), " ($])\n";
 
Last edited:

alcramer

New Member
Messages
53
Reaction score
0
Points
0
Hi--
Don't know if this helps -- you may already have discovered this -- but x10hosting is a little funny about where they want you to upload your Perl scripts. A common practice is to put them in some
subdirectory "cgi-bin" of your root public directory (by "root public directory" I just mean the directory in which your "index.html" is located). When I deployed my site on x10hosting (which worked fine under localhost Apache) I found that the scripts wouldn't run unless I moved them up to my root public directory. Then everything worked. It's like they want you to use a flat-directory structure.
Also you may want to fiddle with file permissions. 755 vs. 777. Good luck!
Al
 

jdw999

New Member
Messages
44
Reaction score
0
Points
0
Got sidetracked by other concerns and today just logging in to keep my account active. Out of curiosity I checked on this thread and was surprised to see five new posts. Had no idea there were some others interested in or knowledgable about Perl.

Anyhow, garrett, I only just now saw the second bit of code you posted, and don't have time to experiment just now. But, you might want to check out an O'Reilly book (if you have not already) called CGI Programming in Perl. It goes into a good bit of detail about CGI and the HTTP environment, which to me was a big bonus in shedding some light on stuff that goes on behind the scenes, so to speak.

If I get time to do so, I will check out the script you posted. Good luck and thanks again. And thanks to al and mission for chiming in. Good to know there are some ppl who know about this stuff and participate in the forums.
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
I'm pretty busy trying to learn about 3 other programming languages right now, but I'll add it to the list, thanks :)
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
I'm pretty busy trying to learn about 3 other programming languages right now, but I'll add it to the list, thanks :)

That's understandable. Perl is fun and hella expressive but parts are tricky to learn and it takes a while to master all of it. (3 ways of calling methods? Really? Yay, I can mess with symbol tables at runtime! Boo, I might need to mess with symbol tables at runtime!) It's nice to see a programming language with aesthetics ([2] [3] [4] [5] [6]).

It's not called a Swiss-Army chainsaw for nothing.
 
Top