Asa Martin <[email protected]> writes: ... > 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.
Theoretically, I could imagine your version being faster since you're giving the compiler more information about the scope and lifetime of the variables involved. Perhaps perl could make better decisions about register usage (I don't know perl internals). I guess they're thinking the variables are created anew each loop iteration (which is what, one increment of a frame pointer or would that hit the heap, assuming it's not optimized out completely?). Someone should measure. Your way is plainly better for readability and maintenance. - Mike _______________________________________________ Boston-pm mailing list [email protected] http://mail.pm.org/mailman/listinfo/boston-pm

