PERL, like riding a bicycle

I haven't written PERL for pay in several years but a popular wiki tool that I'm using (TWiki) uses it.  So on occasion I have to jump back into the PERL world.  A few quick hits that should help me (and you) get up to speed quickly when tracking down a problem.  I'm using indigoperl on win32 with several of the win32 ports of GNU tools (e.g., less)


Getting Help

Thank goodness for perldoc.  Executed via perldoc

or perldoc .  Useful perldoc pages:

  • perltoc - table of contents
  • perlintro - quick syntax reference (see perlsyn for more detail)
  • perlfunc - list of builtin functions
  • perldebtut - perl debugger tutorial.  Covers the basics more than well enough to troubleshoot most problems.

Useful Debugger Commands

Phrased in "Visual Studio" speak for those of us in the Win32 world now..

  • n - step over
  • s - step into
  • r - step out
  • v - display surrounding source code, type again to display more source code
  • . - show next statement
  • c - run until line (the line numbers are listed by v or l)
  • l - list line
  • p $var - prints $var (scalar).
  • x @var - prints @var in a list context
  • x \%var - pretty prints name/value pairs for a hash, also prints any object.

Turns out my particular problem was inside CharsetDetector::detect1().  It was dying when it encountered certain byte sequences.  Quick and dirty solution was to wrap it inside an eval { } (PERL's faked exception handling mechanism - errors stored in $@) then return an empty string.



No comments:

Post a Comment