while (<>) { chop; # avoid \n on last field @array = split(/:/); ... }You can actually chop anything that's an lvalue, including an assignment:
chop($cwd = \`pwd\`); chop($answer = <STDIN>);If you chop a list, each element is chopped. Only the value of the last chop is returned.
Note that, since eval traps otherwise-fatal errors, it is useful for determining whether a particular feature (such as dbmopen or symlink) is implemented. It is also Perl's exception trapping mechanism, where the die operator is used to raise exceptions.
If the code to be executed doesn't vary, you may use the eval-BLOCK form to trap run-time errors without incurring the penalty of recompiling each time. The error, if any, is still returned in $@. Evaluating a single-quoted string (as EXPR) has the same effect, except that the eval-EXPR form reports syntax errors at run time via $@, whereas the eval-BLOCK form reports syntax errors at compile time. The eval-EXPR form is optimized to eval-BLOCK the first time it succeeds. (Since the replacement side of a substitution is considered a single-quoted string when you use the e modifier, the same optimization occurs there.) Examples:
# make divide-by-zero non-fatal eval { $answer = $a / $b; }; warn $@ if $@; # optimized to same thing after first use eval '$answer = $a / $b'; warn $@ if $@; # a compile-time error eval { $answer = }; # a run-time error eval '$answer ='; # sets $@
$foo = q!I said, "You said, 'She said it.'"!; $bar = q('This is it.'); $today = qx{ date }; $_ .= qq *** The previous line contains the naughty word "$&".\n if /(ibm|apple|awk)/; # :-)