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