Just wanted to share why using qr// to store regexes is usually a better idea than using strings...

Today I was told to debug why a night batch failed to complete in the last weeks ...

As it turned out filenames where checked with a list of hardcoded regexes and one of them had a typo. Instead of filter => ".*pl|.*txt" it had ".*pl|*.txt" which was hard to spot among many other regexes and caused a runtime error.

Now using qr would have caused filter => qr/.*pl|*.txt/ to fail immediately at compile time.

And since my colleagues use Komodo which runs perl -c at background (aka flymake-mode in emacs) this would have meant noticing the typo instantly while editing.

HTH!

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

PS: not wanna talk about the other flaws, like why extensions are checked with handcrafted regexes or why exitcodes from batches weren't checked...

Replies are listed 'Best First'.
Re: Good practice: A case for qr//
by morgon (Priest) on Apr 26, 2016 at 02:30 UTC
    One more good practice: Have some tests :-)
      That's like saying use strict ...

      ... or have some tests.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

        Not at all.

        It's meant to say use strict _AND_ have tests.