Optimizing Perl
An anonymous reader writes "Perl is an incredibly flexible language, but its ease of use can lead to some sloppy and lazy programming habits. We're all guilty of them, but there are some quick steps you can take to improve the performance of your Perl applications. This article looks at the key areas of optimization, which solutions work and which don't, and how to continue to build and extend your applications with optimization and speed in mind."
WTF???
/\A\.[\.]+\Z/;
Lameness filter encountered.
Your comment violated the "postercomment" compression filter. Try less whitespace and/or less repetition. Comment aborted.
13. There are times the 'unless' fits right in. Like when the action will take place by default, but have some exception. Like
print $dirname unless $dirname =~
16. Spagheti code is evil, not goto. Since Perl have more flexible flow control, I don't remember to have used it yet, but when coding in C, sometimes I use goto to cleanly escape a function that deals with many resources. It really can make the code much simpler and more readable by avoiding having many exit points.
resource* get_r1()
{
resource r1 = NULL;
resource r2 = NULL;
resource r3 = NULL;
r1 = alloc_resource();
if(r1 == NULL) {
perror("blah");
return NULL;
}
r2 = alloc_resource();
if(r2 == NULL) {
perror("blah");
free_resource(r1);
return NULL;
}
r3 = alloc_resource();
if(r3 == NULL) {
perror("blah");
free_resource(r1);
free_resource(r2);
return NULL;
}
use_resources(r1, r2, r3);
free_resource(r2);
free_resource(r3);
return r1;
}
I much prefer:
resource* get_r1()
{
resource r1 = NULL;
resource r2 = NULL;
resource r3 = NULL;
r1 = alloc_resource();
if(r1 == NULL) goto error;
r2 = alloc_resource();
if(r2 == NULL) goto error;
r3 = alloc_resource();
if(r3 == NULL) goto error;
use_resources(r1, r2, r3);
goto clean;
error:
perror("blah");
if(r1 != NULL) free_resource(r1);
clean:
if(r2 != NULL) free_resource(r2);
if(r3 != NULL) free_resource(r3);
return r1;
}
29. Oh!.. a printout. That makes sense. I just coundn't think of a reason for that lines. It's just that I never chop trees to look at code.