NAME 

perltrap - Perl traps for the unwary

DESCRIPTION 

The biggest trap of all is forgetting to "use warnings" or use the -w switch; see perllexwarn and perlrun. The second biggest trap is not making your entire program runnable under "use strict". The third biggest trap is not reading the list of changes in this version of Perl; see perldelta.

Awk Traps 

Accustomed awk users should take special note of the following:
*
A Perl program executes only once, not once for each input line. You can do an implicit loop with "-n" or "-p".
*
The English module, loaded via
    use English;

allows you to refer to special variables (like $/) with names (like $RS), as though they were in awk; see perlvar for details.

*
Semicolons are required after all simple statements in Perl (except at the end of a block). Newline is not a statement delimiter.
*
Curly brackets are required on "if"s and "while"s.
*
Variables begin with ``$'', ``@'' or ``%'' in Perl.
*
Arrays index from 0. Likewise string positions in substr() and index().
*
You have to decide whether your array has numeric or string indices.
*
Hash values do not spring into existence upon mere reference.
*
You have to decide whether you want to use string or numeric comparisons.
*
Reading an input line does not split it for you. You get to split it to an array yourself. And the split() operator has different arguments than awk's.
*
The current input line is normally in $_, not $0. It generally does not have the newline stripped. ($0 is the name of the program executed.) See perlvar.
*
$<digit> does not refer to fields---it refers to substrings matched by the last match pattern.
*
The print() statement does not add field and record separators unless you set $, and "$\". You can set $OFS and $ORS if you're using the English module.
*
You must open your files before you print to them.
*
The range operator is ``..'', not comma. The comma operator works as in C.
*
The match operator is ``=~'', not ``~''. (``~'' is the one's complement operator, as in C.)
*
The exponentiation operator is ``**'', not ``^''. ``^'' is the XOR operator, as in C. (You know, one could get the feeling that awk is basically incompatible with C.)
*
The concatenation operator is ``.'', not the null string. (Using the null string would render "/pat/ /pat/" unparsable, because the third slash would be interpreted as a division operator---the tokenizer is in fact slightly context sensitive for operators like ``/'', ``?'', and ``>''. And in fact, ``.'' itself can be the beginning of a number.)
*
The "next", "exit", and "continue" keywords work differently.
*
The following variables work differently:
      Awk       Perl
      ARGC      scalar @ARGV (compare with $#ARGV)
      ARGV[0]   $0
      FILENAME  $ARGV
      FNR       $. - something
      FS        (whatever you like)
      NF        $#Fld, or some such
      NR        $.
      OFMT      $#
      OFS       $,
      ORS       $\
      RLENGTH   length($&)
      RS        $/
      RSTART    length($`)
      SUBSEP    $;
*
You cannot set $RS to a pattern, only a string.
*
When in doubt, run the awk construct through a2p and see what it gives you.