Mastering Perl

Mastering Perl

brian d foy

Language: English

Pages: 400

ISBN: 144939311X

Format: PDF / Kindle (mobi) / ePub


Take the next step toward Perl mastery with advanced concepts that make coding easier, maintenance simpler, and execution faster. Mastering Perl isn't a collection of clever tricks, but a way of thinking about Perl programming for solving debugging, configuration, and many other real-world problems you’ll encounter as a working programmer.

The third in O’Reilly’s series of landmark Perl tutorials (after Learning Perl and Intermediate Perl), this fully upated edition pulls everything together and helps you bend Perl to your will.

  • Explore advanced regular expressions features
  • Avoid common problems when writing secure programs
  • Profile and benchmark Perl programs to see where they need work
  • Wrangle Perl code to make it more presentable and readable
  • Understand how Perl keeps track of package variables
  • Define subroutines on the fly
  • Jury-rig modules to fix code without editing the original source
  • Use bit operations and bit vectors to store large data efficiently
  • Learn how to detect errors that Perl doesn’t report
  • Dive into logging, data persistence, and the magic of tied variables

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Tied Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 They Look Like Normal Variables At the User Level Behind the Curtain Scalars Arrays Hashes Filehandles Summary Further Reading 269 270 271 272 277 286 288 290 291 18. Modules As Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 The main Thing Backing Up Who’s Calling? Testing the Program viii | Table of Contents 293 294 294 295

a subroutine call from __ANON__ followed by the subroutine calls I expect to bar() and foo(): Starting program... Dying from bar! at die.pl line 12 main::__ANON__('Dying from bar!\x{a}') called at die.pl line 20 main::bar() called at die.pl line 18 main::foo() called at die.pl line 16 I change my anonymous subroutine to adjust the position in the stack where croak starts its report. I set the value of $Carp::CarpLevel to the number of levels I want to skip, in this case just 1: $SIG{__DIE__} =

the same thing, but stores the results in its own format so it can do several things with them later, such as make pretty code graphs. I call it in the same way by using the -d switch. I have a program that reads the Use.Perl‡ journal entries through its SOAP interface. I run it with the -d switch and tell it to use Devel::DProf as the debugging module: % perl -d:DProf journals Once I’ve run the program, I have a new file named tmon.out, although I can change that with the

don’t give up. Good luck! Who Should Read This Book I wrote this book as a successor to Intermediate Perl, which covered the basics of references, objects, and modules. I’ll assume that you already know and feel comfortable with those features. Where possible, I make references to Intermediate Perl in case you need to refresh your skills on a topic. If you’re coming directly from another language and haven’t used Perl yet, or have only used it lightly, you might want to skim Learning Perl and

Summary I don’t have to hardcode user-defined data inside my program. I have a variety of ways to allow a user to specify configuration and runtime options without her ever looking at the source. Perl comes with modules to handle command-line switches, and there are even more on CPAN. Almost any configuration file format has a corresponding module on CPAN, and some formats have several module options. Although no particular technique is right for every situation, my users won’t have to fiddle

Download sample

Download