For hobby purposes, I have a shared space on a hosting server that is providing, as many of them are, both PHP and Perl CGI. I have read on several places that CGI scripts
I use both Perl and PHP for websites - for historical reasons, mainly Perl at work and PHP at home; I don't think there is a lot to choose between them.
If your pages are mostly fixed HTML with only a small amount of computation, PHP is a bit easier, because it is embedded in HTML anyway.
I find PHP a more disciplined, and therefore sometimes more limiting, language than Perl. PEAR is very similar to CPAN - not as big, I think, but then CPAN is so big that it's got a lot of dross in it.
HTH
Colin
Here is a simple "hello world" example that runs under CGI using the Squatting web microframework:
use strict;
use warnings;
{
package MyApp;
use base 'Squatting';
use base 'Squatting::On::CGI';
}
{
package MyApp::Controllers;
use Squatting ':controllers';
our @C = (
C(
Index => [ '/' ],
get => sub {
my ( $self ) = @_;
my $v = $self->v;
$v->{say} = 'hello world!';
$self->render( 'hello' );
},
),
);
}
{
package MyApp::Views;
use Squatting ':views';
use HTML::AsSubs;
our @V = (
V( 'html',
layout => sub {
my ( $self, $v, @yield ) = @_;
html (
head ( title( 'My CGI App' ) ),
body ( @yield ),
)->as_HTML;
},
hello => sub {
my ( $self, $v ) = @_;
p ( $v->{say} );
},
),
);
}
use CGI;
my $q = CGI->new;
MyApp->init;
MyApp->relocate('/cgi-bin/myapp.cgi');
MyApp->cgi($q);
Save as "myapp.cgi" and place in your cgi-bin.
If you use hosting, in many cases PHP would be run as CGI too. If you don't want to run FastCGI or mod_perl, you can use CGI::Application framework. CGI::Application will run with FastCGI or mod_perl too, but unlike Catalyst will run as CGI too. Both Catalyst and CGI::Application also can be run with their own web servers.
Both PHP and Perl have their moments, but this is truly subjective. Perl has massive frameworks available on CPAN which can make it work as well, or better, than PHP, even in a purely CGI environment. At the same time, PHP has a large following, and a ton of out of the box features to make website programming simple. The choice, to me, boils down to personal preference. I personally prefer to use Perl than to muck about with trying to find all of the functional ways to do things in PHP. Good luck!
This is a fairly subjective issue for deciding what to use for a hobby. I decided to learn Perl as a hobby after looking into PHP and not liking the fact that I could not read most of the PHP out there and being daunted by the list of builtin functions.
The first few things I did were CGI scripts for contact forms and a photo album generator. I was on a cheapo shared hosting plan and I was not getting any performance problems so the performance issue never came into play.
Instead, the existence of comp.lang.perl.misc and CPAN ensured that I never reconsidered my decision not to delve into PHP.
In the mean time, I realized most of the content on my web sites is static once generated, so now I write Perl scripts to generate the content offline.
So, my answer is, pick a small project, anything will do, and implement it using Perl and appropriate CPAN modules and see if you like it.
Whether you use PHP or Perl is moot from a scaling perspective much in the way that the difference between a webapp written in PHP and C is moot. If the difference really mattered, we'd all be writing C, or assembly.
PHP is slow, but that isn't stopping Wikipedia, Facebook, and Yahoo from using it extensively.
There are two major reasons it doesn't matter, from a scaling perspective, which language you choose:
Pick the language that you and your team can develop in most efficiently.