Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Perl >> Snippet

32 Common mistakes


Adapted 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 .