Utf8 in web perl application (LAMP)
Wednesday 2 December 2009 @ 6:45 am

Making a correct utf8 web application in LAMP (Perl) is not easy. There are lots of dangerous traps along the way.

We need to take care of source code encoding, web forms data – inputed by user –  encoding, mysql encoding, displaying data (writing) encoding, and perhaps also take care of data taken from disk files.

First, we need to take care of source code, if we want to write there something like

$var = “zażółć gęślą jaźń”

we need  to use utf8

The use utf8 pragma tells the Perl parser to allow UTF-8 in the program text in the current lexical scope

Do not use this pragma for anything else than telling Perl that your script is written in UTF-8.

use utf8 is not a magical trick to fix all problems with utf8, just a beginning of the journey…

We must have a good code editor or IDE that understands utf8. It will be also nice to have possibility to open files with other other encodings and convert them to utf8. For unix/linux there is for example KDevelop, and many other tools. For windows, there are many editors too. See: http://en.wikipedia.org/wiki/Comparison_of_text_editors#Unicode_and_other_character_encodings and http://www.alanwood.net/unicode/utilities_editors.html

When using use utf8 remember to save code in utf8 encoding!

To be continued…

Comments (2) - Posted in work by  

Website authorization – my solution
Wednesday 11 November 2009 @ 6:37 am

I wrote about wondering how to make “login” to a dynamic website in Perl. The best solution advised by http://perldesignpatterns.com/?WebAuthentication was to make a temporary token: “cookie with an authorization token. Store the token in the database along with an expiration time separate of the cookie. The token should be random generated and completely seperate from the password but handed out when the password is validated. This is the best case;”, but it was overshot for now, so I settled up for this scheme:

Whan user registers, his password is stored as md5 digest in database. Salt is generated – string of eight random letters, numbers etc.I use Crypt::PasswdMD5 qw(unix_md5_crypt);

When user logs in, password is checked-  crypted using crypted pass from database as salt:

if ( $cryptedpassword eq unix_md5_crypt($password, $cryptedpassword)) {

and if it is ok, cookie is stored with user ID and crypted password.

The cookie is then checked on every page, whether it contains the crypted password from database.

Well, this is my idea of doing it for now, already implemented, I feel a bit unease about that – what is the point of crypting password and storing it crypted, as it really matters whether the pass from cookie is equal to pass in database – it could be not crypted and it would work the same way.

The only advantage is that the password is not stored in cookie – but it is not needed, as just the digest is needed to pretend to be logged in.

What do you think?

Comments (4) - Posted in cpan,work by  

Website login with Perl
Tuesday 27 October 2009 @ 6:55 am

Lately I was thinking about implementing logging (as in login/password) into a website with Perl. I mean, that I want to have a dynamic website, where users can login using login and password and do some stuff.

After googling for “how to make login site” mostly PHP session solutions came up. When I added “perl” to that google query, half of results was about logging into someone’s website (wget, LWP, WWW::Mechanize etc) and not making a login feature in existing dynamic website. Search for “perl authentication” found more relevant stuff.

Some pages suggested using .htaccess. Bleh. Beside, I want to have user in a SQL database.

One result pointed to CGI::Session on cpan. Nice. CGI::Session::Auth – nice too 🙂 There is also Apache::Session to be found on cpan.

There was also a hint, to find a perl web forum script and see how it is done there. We’ll, I did it with one forum script, and found that user login and crypted password is stored in a cookie. Nice.

There also books that talk about how to do web authentication: Perl for Web Site Management or CGI programming with Perl

Here we have some design patterns: http://perldesignpatterns.com/?WebAuthentication and also: http://perldesignpatterns.com/?SessionPattern and http://perldesignpatterns.com/?PerlDesignPatterns . Even nicer 🙂

But I still look for ultimate “how to” with examples about authorizing users (register, login, remind password etc.)  into some kind of dynamic website with Perl. Any hints?

Comments (1) - Posted in work by  

Rocketaware – perl resources
Wednesday 21 October 2009 @ 6:56 am

Often, when I googled for information about Perl, that website came up in search results: http://www.rocketaware.com/perl/ .

It looks quite ugly, like but is great source of information about perl, especially for beginners. Take for example this page: http://www.rocketaware.com/perl/onepage.htm – it list all that cryptic “Short-hand variables.”, and also functions and operators.

This page does not only seem to be old, it is old. For example this page: http://www.rocketaware.com/perl/perlfaq4/Why_aren_t_my_random_numbers_ran.htm points to http://www.perl.com/CPAN/doc/FMTEYEWTK/random , where you can read (at least now) that:

Note that the old documentation, often advertised as www.perl.com/doc or www.perl.com/CPAN/doc, has been removed from CPAN as of November 2001 because it had not been updated for several years”.

The documentation in not-so-archaic distributions of perl points to this place instead: http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz where the old docs are stored. The rocketaware site seem to not be aware of those year 2001 changes, and in footer one can read: “Copyright 2000, Forrest J. Cavalier III.”

So to sum op, this site is:
– old
– ugly
– useful (at least if you don’t mind using perl as it was year 2000)

The page http://www.rocketaware.com/perl/onepage.htm alone makes this website worth recommendation.

Comments (0) - Posted in work by  

Having nice background colors in Spreadsheet::WriteExcel
Wednesday 7 October 2009 @ 10:03 am

If you want to make Excel spreadsheet using perl module Spreadsheet::WriteExcel with, for example, orange or yellow backgorund in some cells, you can use the built-in palette, but the colours there may burn your eyes 🙂

How to have nice colours in spreadsheets: use set_custom_color($index, $red, $green, $blue)

For example:

my $light_orange = $workbook->set_custom_color(43, 255, 226, 171);
my $ligth_yellow = $workbook->set_custom_color(42, 255, 255, 204);
my $light_purple = $workbook->set_custom_color(40, 225, 204, 255);

Comments (0) - Posted in work by  

Working as perl developer – telecommuting
Wednesday 16 September 2009 @ 6:55 am

Wow,this would be four weeks  since joining ironman challenge.

Recently I was wondering about pros and cons of working as Perl developer in two ways:

1) In office, in a big company

2) by telecommuting or other way working in other place that the employer is

They have both advantages and disadvantages.

In office, advantages are: nice colleagues (I am lucky to have them now), free coffe and tea and milk and sugar and…, constant daily routine, a bit of fun/laughing/relax everyday (face it, noone works 100% of the time – it would be also bad for their creativity, physical and mental health etc – for example we are advise to stop looking at minitor every hour for about 5 minutes), fixed hours with some flexibility. Disadvantages: daily commute, trafic jams, earnings based on world region/country, even city.

Telecommute: higher earnings, possiblity to geoarbitrage (I mean earning in one country, living in another – cheaper, or even constantly travel – for more ideas on this see: 4HWW ), no commute, no traffic jams. Disadvantages: I assume you are paid on results – so if you screw up, you have free work overtime. No colleagues, no free coffe nor tea. Your home is your work – that is not good. Unless you rent some office space or use shared working place. Hard to say more, I never worked like this.

What do you think?

Comments (3) - Posted in work by  

« Newer Posts