Softpanorama
(slightly skeptical) Open Source Software Educational Society

May the source be with you, but remember the KISS principle ;-)

Softpanorama Search

Introduction to Perl for Unix System Administrators

(Perl without excessive complexity)

by Dr Nikolai Bezroukov


Prev | Up | Contents | Down | Next

2.5. Typical Errors and pitfalls

Most typical for beginners Perl errors that probably should be checked before submitting script to the interpreter includes:

  1. Absence of semicolon at the end of statement;

  2. Absence of prefix $ from the scalar variable like in if (i==1) {...}

  3. Missing quote;

  4. Usage of "==" instead of "eq" and other operators ( != ne, < lt > gt, etc.)

  5. Usage of  @ instead of $;

  6. A single statement after if or for;

  7. Wrong brackets in hash (should be {}).

A very typical mistake connected with double-quoted literals is putting in it a email address (or group of e-mail addresses). The same applied to backquotes, for example

` cat letter | mailx -s test myself@mydomain.my`;

Here @mydomain will interpreted as an array with very undesirable results.  The correct form should be

`cat letter | mailx -s test myself\@mydomain.my`;

or

to_addr='myself\@mydomain.my;

`cat letter | mailx -s test $to_addr`;

 

More extensive collection of typical errors can be found in man page perltrap



Copyright © 1996-2009 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Site uses AdSense so you need to be aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

Disclaimer:

Last modified: September 05, 2009