In Perl, a subroutine or other block structure that returns a value gives back the last evaluated expression, but if you’re not careful you might not recognize what that last evaluation actually is. It’s not necessarily the last statement in the block; it’s just the last one that you actually execute. For this Item, forget about the best practice of using explicit returns. You should do that for precisely the reasons you will see here, but you can’t learn about the problem by avoiding it. Continue reading “Know what your the last evaluated expression actually is.”
Report any errors you find in Effective Perl Programming
Now that you should be able to get Effective Perl Programming, let us know if you find a problem. We’re going to keep a list of errata on this site. Make sure you check the current list before you spend your time reporting it to us. When you do find something, you can send it to errata at effectiveperlprogramming dot com.
Use DBI_TRACE to follow DBI’s work.
There is a lot going on when you use DBI to interact with a database. Tack on a few layers of abstraction from Object Relational Modelers (ORM’s) such as DBIx::Class and you can end up with a tricky maze of subroutine calls to dig through when you need to track down issues. DBI
comes with a built-in tracing feature to make it easier though. Continue reading “Use DBI_TRACE to follow DBI’s work.”
Effective Perl Programming is now in stock at Amazon!
Josh and I got hard copies of the Effective Perl Programming, Second Edition last week, and Amazon says they are in stock.
Effective Perl Programming’s table of contents
Here is the final table of contents for Effective Perl Programming, 2nd Edition. The “Item” references in our blog entries refer to the items in the book. We also have a map from the Item numbers in the first edition to those in the second, but we’ll have to do a little work to make those look nice for the blog. Continue reading “Effective Perl Programming’s table of contents”
Interact with the system when Perl isn’t enough
Usually, you want to do as much of your work inside your Perl program as you can. CPAN has a wealth of modules that accomplish many tasks, including those that you normally do very easily from the command line. In the cases where you can’t find a module, you might not be able to improve on the command-line siutation for complicated tasks. Perl is, after all, a glue language, so you don’t always have to do everything in Perl. When you decide to use an external program, there are many Perl features waiting to help, although you have to choose the right one for the job. Continue reading “Interact with the system when Perl isn’t enough”
InformIT has an Effective Perl Item: Process HTML with a Perl Module
As part of the promotional package for Effective Perl Programming, I wrote Process HTML with a Perl Module for InformIT. It’s just like the Items that you see here, but on another site.
Use /gc and \G in matches to separate alternations in separate, smaller patterns
Perl keeps track of the last position in a string where it had a successful global match (using the /g
flag). You can access this position with the pos
operator. With Perl 5.10, you can use the /p
switch to get the per-match variable ${^MATCH}
instead of the performance-dampening $&
: Continue reading “Use /gc and \G in matches to separate alternations in separate, smaller patterns”
Know the difference between regex and match operator flags
The match and substitution operators, as well as regex quoting with qr//
, use flags to signal certain behavior of the match or interpretation of the pattern. The flags that change the interpretation of the pattern are listed in the documentation for qr//
in perlop (and maybe in other places in earlier versions of the documentation): Continue reading “Know the difference between regex and match operator flags”
Install scripts from distributions
Perl’s distribution system is quite powerful and supported by a variety of tools that can make life easier for you. Most people tend to think that “distributions” are synonymous with modules, but that’s only one of the uses for distributions. Continue reading “Install scripts from distributions”