Posts

Showing posts with the label Perl

Perlbrew saved the day

After an insanely long period of silence, I am writing another blog entry. I couldn't contain my excitement with what I learnt today and hence this post. I had to upgrade Perl installation in my Linux host and I visited Perl.org to download and install Perl. It was suggested to make use of the perlbrew to install and manage different versions of Perl under your home directory. I gave it a try and it was incredibly simple to upgrade the Perl installation in my box, without screwing up the old installation (which I still need for some of the old scripts I have). If you haven't tried it yet, I would strongly recommend.

Global Interpreter Lock in Python

Recently we were having an interesting discussion in our team about the threading and performance in Python. One of the key concerns was the Global Interpreter Lock (GIL) in Python. GIL is acquired before any thread accesses any of the Python objects. So if you are writing any C extensions and if you would like to manipulate any Python object, you must first acquire the lock and then only you can read/write/modify any object. Due to this, you will always have considerable of your code sequential. There is a lot of discussion about GIL on the web. You will particularly find this page useful . Someone suggested that Lua , by design, doesn't have any such constraints. It performs very well when it comes to multithreading. As I don't have much experience in programming in Lua, I don't know if that claim is true or not. I am also not sure if Perl has any such global locks issue. I tried to Google it, but didn't find anything useful.

Difference between for (<STDIN>) and while(<STDIN>) in Perl

Can you tell if there is a difference between "for (<STDIN> ) { BLOCK}" and "while( <STDIN> ) {BLOCK}" in Perl? They both might look like similar. When I used the first construct and gave a huge file as input, my Perl program crashed. When checked the top output after starting the program, I figured that the RSS size of the program kept growing and eventually crashed. Hmm ... when I switched to the second construct, not only the program ran successfully but also used less memory! The difference is that for construct reads the entire file before it enters into the loop. But the while construct reads only a part of the file and buffers it. I wrote a program to count the number of lines in an input file in both the flavors. while loop version took only 1MB where as for loop version took 149 MB for an input file of 79 MB. On top of it, the while loop version took on an average 1.36 seconds, and the for loop version took around 2 seconds. So if you are writ...

Learning Perl - ebooks & resources

I ventured into brushing up my Perl knowledge, as its really a long time since I read a book on Perl. I found the following resources useful: Beginning Perl by Simon Cozens. I think this is one of the best books to begin Perl programming. The perldoc website . This is not really book or a cogent order of tutorials, but an excellent reference once you are familiar with the basics. A collection of resources to learn Perl from the www.freeprogrammingresources.com website. And there is always perldoc , to refer to topics/functions/modules off line.

Installing modules in Perl

The easiest way to install the Perl modules from CPAN is to use the CPAN module. For e.g. the following command will install the XML::Simple module. perl -MCPAN -e 'install XML::Simple;' If you wish to view the readme file for a particular module, try this command (I am viewing the readme file for XML::Simple module): perl -MCPAN -e 'readme XML::Simple;' Another useful way of running CPAN module interactively is to give the following command: perl -MCPAN -e shell Once you get the shell prompt "cpan>", try "help" to get to know more useful options. To know more, refer here .