Back to Top

Monday, October 09, 2006

Why do I love perl?

Before you accuse me of being a fanboy, I must say that I know that every language has bad sides, but also some incontestable merits. I want to talk about two perl related stories here. They both are a kind of short how-tos, and the morale of the story is that you can find ready made libraries for perl for almost anything at CPAN.

The first story is as follows: I maintain an internal website and recently the need came up for the users to write small scripts which then needed to be executed on certain time intervals. My first reaction was: no way am I allowing such a thing, although I trust my users :). Then I started looking for scripting languages which allowed restrictions to be placed on the scripts. A colleague suggested that I use a trimmed down version of Python by deleting all but the needed few libraries, but curiously the official Python distribution recreates the files if they are deleted (probably it considers that it was damaged and tries to repair itself). Then I thought that I compile a custom version of the LUA interpreter, but I felt lazy. Luckily I found the Safe perl module and now I can execute scripts safely. The morale: perl can do almost anything, has libraries for almost everything and it's almost sure that somebody did it before so play around with google before writing code.

The second story was: I needed to pull some files using SFTP. There is a nice module (as for almost everything!) on the CPAN, but the problem was that it was not available through the ActiveState PPM repositories (yes, I needed to use it on a Windows machine). Grumbling I ended up scripting WinSCP (which is a great program by the way), but calling an external program isn't a good idea because (a) if there are errors you'll have very limited knowledge of what the problem exactly was (while normally you could just hook the DIE and WARN handlers and get very detailed information about the problem). (b) it is a security risk because of the braindead implementation of windows where the current directory is in the path so you might end up executing the wrong program (c) there are problems with passing parameters to command line programs because you need to remember to quote them and so on. Then I found a blog post which explained that the cryptographic packages are not included in Perl because of Canadian export law (ActiveState being based in Canada - see, I give all kind of useless trivia information here), but you can use alternative repositories (which I already knew from the time when I installed Log4Perl). So if you need these packages and are stuck on Windows, just start your perl package manager and do a rep add Winnapeg http://theoryx5.uwinnipeg.ca/ppms/. Now you can install packages like Net-SSH or Net-SFTP without a problem. Morale: governments make stupid technological laws and there are alternative package sources.

Happy perl coding!

1 comment:

  1. Anonymous11:34 PM

    Perfect! I've been trying to get Net::SFTP installed on a Windows box and was having trouble with the CPAN version.

    ReplyDelete