|
Contents
16. Common Goofs for NovicesAdapted from Programming
Perl, page 361.
- Testing "all-at-once" instead of incrementally, either bottom-up or
top-down.
- Optimistically skipping
print scaffolding to dump values and
show progress.
- Not running with the
perl -w switch to catch obvious
typographical errors.
- Leaving off
$ or @ or % from the
front of a variable, or omitting & when invoking a subroutine in Perl 4.
- Forgetting the trailing semicolon.
- Forgetting curly braces around a block.
- Unbalanced (), {}, [], "", '', ``, and sometimes <>.
- Mixing '' and "", or / and \.
- Using
== instead of eq , != instead
of ne , = instead of == , etc.
('White' == 'Black') and ($x = 5) evaluate as
(0 == 0) and (5) and thus are true!
- Using "else if" instead of "elsif".
- Not chopping the output of backquotes
`date` or not chopping
input: print "Enter y to proceed: ";
$ans = <STDIN>;
chop $ans;
if ($ans eq 'y') { print "You said y\n";}
else { print "You did not say 'y'\n";}
- Putting a comma after the file handle in a print statement.
- Forgetting that Perl array subscripts and string indexes normally start at
0, not 1.
- Using $_, $1, or other side-effect variables, then modifying the code in a
way that unknowingly affects or is affected by these.
- Forgetting that regular expressions are greedy, seeking the longest match
not the shortest match.
|
|