in reply to Best Perl Practices reviews?

Note to AM ... come out from under the rock. Although PBP is a good book, sometimes I feel TheDamian jumps through some pretty funky loops to get his point across. For your first foray into best practices (or idiomatic perl), I would suggest Effective Perl Programming - which by the way has a slightly better rating (and from more reviewers) than PBP.


Replies are listed 'Best First'.
Re^2: Best Perl Practices reviews?
by Fletch (Bishop) on Dec 15, 2006 at 14:01 UTC

    An excellent recommendation, just keep in mind that EPP is getting a little long in the tooth. It came out in pre-5.005 days so some recommendations are no longer really optimal. An example that comes readily to mind since I just happened to be thumbing through my copy the other day: it recommends avoiding the overhead of /o on dynamically generated regexen by creating an anonymous coderef using string eval and calling that instead.

    ## not the exact code, but a close facsimile from memory: sub make_matcher { eval qq{sub { \$_[0] =~ /$_[0]/o } } } my $matcher = make_matcher( "dynamic" ); if( $matcher->( "dynamicorama" ) ) { # ... }

    Nowadays you can use qr// and get the same performance with less scaffolding (presuming Perl newer than 5.6.1 if I'm recalling correctly from the recent threads here on the topic).

    So keep in mind the vintage of the advice. 85%+ of it is probably still germane as is, and the remainder is sound underneath but needs slight tweaks. Of course now I probably should actually get around to swiping a coworker's PBP and reading it this weekend. :)

      qr// is first available in 5.6.0.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊