The Portuguese Perl Workshop is back, the event will be held on October 9th and 10th in Lisbon, Portugal. Featuring Dancer2 training class with Alexis Sukrieh, and AnyEvent and Coro GreenThreads Tutorials with Pedro Melo.
This weekend I gave a presentation at OpenCert 2010 about the Perl testing ecosystem, this was an article I wrote with ambs++ and jjoao++. The article can be found on the conference site here.
The fork function is a very powerful tool used among many languages. Unfortunately It's not that common among Perl scripts, maybe because most scripts don't really have a need for it. But it's a handy trick to keep inside your hat.
Fork creates a new process running the same program, usually the process that calls the fork is named the parent process, and the created process is named the child process. The fork function returns 0 to the child process, and the newly created process pid to the parent. Using fork can be as simple as:
Everyday the Internet becomes faster, and everyday new and more complex content is provided via web applications. The problem is that sometimes (maybe most of the times) these rich and complex content applications aren't fast enough to answer big flows of requests. One trick that is often used to improve throughput of slow applications is caching. Instead of always processing requests, that often require some data from one or more external sources, a possible solution is to cache the entire output to answer upcoming requests, or cache smaller components that can be used together to produce…
Grep is another Perl's great built in function, one of the things I use it most is to check if I can find an element on a list. For example, instead of something like
my $found = 0;
foreach (@list) {
$search eq $_ and $found++;
}
I prefer to use something like:
my $found = grep {$search eq $_} @list;
Code is simpler and more elegant, there's no significant performance from using one or another, although grep seems to actually run faster if you want to squeeze all the crumbs: