Ten Essential Development Practices

Damian Conway is an author of Object Oriented Perl resently published on Perl.com an very interesting article – Ten Essential Development Practices. There are 10 useful and helpful recomendations how to produce a good-looking Perl code. Damian Conway is a great man in Perl community. So, you can trast him and to consider his opinion.
Those tips came from his new book which was published O’Reilly: Perl Best Practices. Think that book should stay together with Effective Perl Programming on bookshelf each Perl developer

The glance on PHP through Perl

One month ago I started to customize SugarCRM for our company. This is a very good, hight quality software. But it ‘s based on PHP but I’ve developed on Perl during last four years. I’m not going to say “PHP is shit, Perl forever!”. I’d like just to share my impression of PHP as Perl developer.
And sometimes I’m a little bit confused about PHP. One example you can see bottom:

var $list_fields = array('id', 'first_name', 'last_name', 'account_name',      
'account_id', 'title', 'email1'
, 'quote_role'
, 'quote_rel_id'
, "team_id"
, "team_name"

, 'invalid_email'
);

This is a definition of some array (it’s disgasting to put each element in the quotes and use key word ‘array’). Strange isn’t it? I suspect that PHP didn’t ignore last comma in the array (Perl could do it from his birthday I guess). Thas’s way PHP developers made that trick to have possibility to drop any array’s elements without getting errors.

How to use constants in regexp.

When it needs to create various choises according to someone variable it’s reasonable to build a shitch block:

sub test {
my $var = shift;
SWITCH: for($var) {
/^1$/ && do { do something for case 1 ... ; last SWITCH;};
/^2$/ && do { do something for case 2 ... ; last SWITCH;};
/^3$/ && do { do something for case 3 ... ; last SWITCH;};
}
}

But what will happend if you’ll decide to swap case 2 and case 3? You should make changes in your code.

Continue reading How to use constants in regexp.

Embperl + CGI = problem with upload of files

Recently I’ve spent a half of working day to find what was happened with uploading of files in our web server.
We use Embperl to build dynamic web pages and I’d like to say many thanks to Gerald Richter who is an author of Embperl. My mistake was I didn’t upgrade Embperl till latest version or at least I had to read change logs of new versions. Because, my problem is related with module CGI.pm 3.01+ and Embperl lower than 2.0b11. Embperl uses CGI to upload files.
As you can know, when a web from which has enctype=”multipart/form-data” and control to upload a file is submitted that file is stored in temporary directory and a target script receives file handler which points on that file. When CGI-object was destroyed the uploaded file was removed from temporary directory (this is a bug) and the script couldn’t read uploaded file.
The strange thing was I saw only warning in error log:

Warning in Perl code: readline() on closed filehandle fh00001C%3Afts
eceivePBW036H3.023

Well, the moral is if you have some Open Source parts in your application you should use only stable versions or follow by development

VideoGuide Meditation

The first version of VideoGuide was released about two months ago. Since that time I didn’t have enough time to improve it. I hope that VideoGuide can be useful for somebody. That’s why I’m planning to do a next release of VideoGuide at the end of February (hope it will be done).
To improve VideoGuide first I’ve fixed many bugs which I’ve discovered there (Unfortunately I don’t have anybody to test it and I do it myself).
Second step is implementing new features:
– separate all VideoGuide users on groups: users, editors, moderators and administrators;
– assign each group specific permissions;
– allow people create accounts on VideoGuide;
– implement a sending some notifications by email: new movies, some news, information related with users etc;
– refresh properties of specified movie or person via web interface;
– add new movies and persons via web interface;
– improve rating and statistic functionality and etc.
Also, I’ve decided to move web part of VideoGuide from simple Embperl to Embperl::Object. It will able to build more flexible and scalable user interface.
And I’m going to change disign of VideoGuide to make it more simple, functional and attractive.
So, let’s wait till en of February to see what will be done.

IMDB Top 250

I’ve created a simple Perl script which retrieve a top of 250 IMDB movies which voted by IMDB users. That top is an array each element of which is hash included movie title, production year, user’s rating, number of votes and IMDB movie code. The source of that script is here. Also, I’ve added IMDB Top ten on the cinema page.
All suggestions will be appreciated!