Home arrow Perl Programming arrow Page 4 - Perl 101 (Part 1) - The Basics

To Err Is Human...To Debug, Divine! - Perl

Known as much for its confusing, often oddball, syntax as for itsefficiency and speed, Perl has a mystique that very few languages canmatch. This first article in a new series gives novice and intermediateprogrammers an introduction to the basics of the language.

TABLE OF CONTENTS:
  1. Perl 101 (Part 1) - The Basics
  2. ...And The Little Language That Could!
  3. Your First Perl Program
  4. To Err Is Human...To Debug, Divine!
  5. What's Next?
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 16
May 23, 2000

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
Perl also comes with a very powerful debugger, which alerts you to mistakes in your code. As an example, try omitting the last double quote from the example above and run the script again. You should see something like this:
Can't find string terminator '"' anywhere
before EOF at ./test.pl line 5.

As you can see, the error message tells you pretty much all you need to know to find and squash the bug. Of course, all Perl's error messages aren't quite that informative - some of them are liable to sound a lot like Greek spoken backwards, especially if you're a novice. And so it's a good idea to use the "-w" flag when running your program - this flag tells the debugger to print extra warnings when it encounters an error.

Take a look at the following example, which runs the Perl script above with the "-w" flag:
#!/usr/bin/perl -w
# Synthesis
print ("Hello there! And what are you doing ",
1+1, "night, baby?n);

If you run this program, here's what you'll see:
syntax error at TEST line 5, near "print"
Unquoted string "doing" may clash with future reserved 
word at TEST line 5.
String found where operator expected at TEST line 5, 
near "doing ", 1+1, ""
(Do you need to predeclare doing?)
Bare word found where operator expected at TEST line 
5, near "", 1+1,
"night"
(Missing operator before night?)
Unquoted string "night" may clash with future reserved 
word at TEST line 5.
Unquoted string "baby" may clash with future reserved 
word at TEST line 5.
Unquoted string "n" may clash with future reserved 
word at TEST line 5.
Execution of TEST aborted due to compilation 
errors.

Of course, there is sometimes such a thing as too much data...

 
 
>>> More Perl Programming Articles          >>> More By Vikram Vaswani and Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PERL PROGRAMMING ARTICLES

- Perl Turns 25
- Lists and Arguments in Perl
- Variables and Arguments in Perl
- Understanding Scope and Packages in Perl
- Arguments and Return Values in Perl
- Invoking Perl Subroutines and Functions
- Subroutines and Functions in Perl
- Perl Basics: Writing and Debugging Programs
- Structure and Statements in Perl
- First Steps in Perl
- Completing Regular Expression Basics
- Modifiers, Boundaries, and Regular Expressio...
- Quantifiers and Other Regular Expression Bas...
- Parsing and Regular Expression Basics
- Hash Functions

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: