for(my $i = 0; $i < 10; $i++) { # Note to reader: Yes, could have used a trinary here, but those a +re hard to read # and therefore forbidden in my codebase print "$i is "; if(!iseven($i)) { print "NOT "; } print "even\n"; }
The easiest code to read does not have to be read at all because the comments tell you what's happening. If one must write readable Perl then one should use its features instead writing something that looks like C. This is more perlish and way easier to read:
for (0 .. 9) { print "$_ is "; print "NOT " if not iseven($_); print "even\n"; }
Code should be optimized for efficient execution more than readability. Here Perl does both, since creating blocks is more expensive than postfix logic, especially inside loops. Peace
In reply to Re^2: 5.40 released
by Anonymous Monk
in thread 5.40 released
by hippo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |