![]() |
|
This subtitle is for PHP programmers who wish to learn Perl. I decided to write it because in theory PHP and Perl are both script languages which have a lot in common, yet there are many PHP programmers who find Perl difficult, if not impossible to learn. (Interestingly this is usually not true vica-vesa.)
I assume:
- you know PHP well
- you do not know Perl, but wish to learn it
- you have access to a computer where you can run the Perl interpreter
Most of the time I will be comparing PHP constructs with theis Perl equivalents. Later it's going to be about Perl constructs and features that you do not find in PHP. Enjoy!
We had a hosting server which ran two instances of HTTPDs: one for administration purposes and one for the websites we host. Recently this server was upgraded from a very old Redhat 8 to Fedora (Core) 7. I have recreated many of the configs, and run into some trouble setting up those two instances of Apache (actually Apache 2.2).
(FYI, the two instances are needed for security and performance reasons: the admin server loads mod_perl and some other big modules, running as a normal user, while the httpd for our users have nobody privileges and it had mod_php and a few other small modules loaded. As the matter of fact I have yet another webserver as a reverse proxy on this machine, but let's not go into that now.)
Anyway, the trouble was that when I tried to shut down one of the servers, it took down the other one as well. I had two separate configurations, different DocumentRoots, PID files, and so on.
Without going into too much details, I have tracked down this problem to two things. First is the init script that comes which Fedora. Line 74, in /etc/init.d/httpd. See here:
stop() {
echo -n $"Stopping $prog: "
killproc -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}The task: get an image file, and resize it so that the resulting image (thumbnail) fits in a predefined rectangle without its proportions distorted. We should be able to handle as many image formats as possible.
Without much ado, let's see the code first.
This subtitle is about the Perl (Perl 5) programming language, more precisely about some typical tasks one encounters while programming in Perl.
More »
This subtitle is about PET, a Perl application server and RAD environment for web programming. It is similar in many concepts to Tomcat for Java, Rails for Ruby or Zope for Python. There is also a resemblance with Apache::ASP or Catalyst.
PET uses the excellent TT2 as its templating engine, and is built upon a few gazillion CPAN modules. It can be run in different ways, but in production, it is usually run as a daemon, and must be coupled with a webserver that has FastCGI connectivity.
Currently PET only supports Linux. Please see some incomplete and outdated docs for more info.
I am going to include some actual trick and examples here, the purpose being to show what you can achieve using PET.
A very typical web programming task is to take a directory which contains a bunch of images, and create a thumbnail gallery out of it. The Album module does this very professionally, and an actual industry - TGP sites - is built around this idea.
In theory, it is relatively easy to create an album. All you have to do is to list the directory, get the images, resize them and then display the thumbnails on a (HTML) page with links to the original images. So let's make this easey in practice, too!
Using a few PET built-ins, I am going to show you how to create an album without writing any Perl code - using only 6 lines of code. We will have a page list.pet which lists the thumbnails, and another one called show.pet, which shows the big (original) image.
| 1. |
Perl-2-PHP
2008, Január 21., 19h |
| 2. |
Running multiple instances of Apahce (httpd) on Fedora
2007, December 14., 21h |
| 3. |
First recipe - creating thumbnails
2007, November 19., 23h |
| 4. |
Perl blog - what's this?
2007, November 19., 20h |
| 5. |
PET tricks
2007, November 17., 0h |
| 6. |
Creating a TGP-like gallery using PET in 6 lines
2007, November 17., 0h |
| Title: | Paz |
| Visited: | 3944 |
| Uploaded at: | 2003-12-07 05:25:52 |
| Title: | Jehova guarda a los sencillos |
| Visited: | 1281 |
| Uploaded at: | 2003-10-19 04:04:10 |