punkwalrus (punkwalrus) wrote,

Perl - Advanced Perl Class - Day 3

So far, so good. I have learned a LOT, and filled in some small gaps that will not only save me time, but given me shortcuts that will make me a better programmer.

Part of what I learned so far is formatting, which while a basic issue, was one I never could wrap my head around. We're also working with Object Orientation in Perl, and how it differs from real OO programming. I learned how to make my own modules (it's that simple?).

Another series of lesson were based on error traps and tracing bugs in your perl scripts, which should be a basic thing, IMHO. It alwasy seems that I get "How to find bugs in your programming" lessons are only taught in "advanced" classes of any programming language I learned (VB6, .NET, Perl, hsk scripting, etc...). Here's just a taste:

You may know warn() and die() will dump out an alert when something goes wrong (or at least, you should have them in your code), but someone came out with a better module, which I think is standard in almost all Perl distros, called Carp. Carp/croak/confess not only tells you where the error occured, but also what called the fuction, like suppose you get an error a file can't be opened, and you know it's in a subroutine, but you don't know WHAT called the subroutine. Well, just add Carp!
use Carp;

# Like warn or die, but will tell you where the sub was called, not 
# just where in the sub the error occured

carp(); 	# Like warn(), but from perspective of caller;
croak();	# Like die(), but from perspective of caller;
confess();	# Total nested stack dump of all subs, vars, etc...

Check out the link, this is a very helpful tool.
  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded