I was going over some code at work and I suggested the following code
changes while processing a four column file with columns that contain
domain, subdomain, rule, and label. What those fields actually mean
are irrelevant to this discussion, although they're all short character
strings. Suffice to say, those names are meaningful to anyone with knowledge
of the file. This is the original code:

my ($line, @rules);

while ($line = <FH>) {
    chomp $line;
    @rules = split("\t", $line);

.... do stuff with $rules[0], $rules[1], $rules[2] and $rules[3] ...

Here were my proposed changes:

while (my $line = <FH>) {
    chomp $line;
    my ($domain, $subdomain, $rule, $label) = split("\t", $line);

.... do stuff with $domain, $subdomain, $rule and $label ....

I was told that "predeclaring" the variables outside the loop saved on
memory allocation, and that using @rules instead of four named variables was
also more efficient. I had never considered that this could be the case, and
said I didn't think this was true, but didn't really know.

Any thoughts on this? We're using perl 5.10.0

Thanks,

Asa

_______________________________________________
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to