Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 3. Regular Expressions > Item 39. Compile regexes only once

Item 39. Compile regexes only once

The regular expressions for most pattern matches and substitutions are compiled into Perl’s internal form only once—at compile time, along with the rest of the surrounding statements. In the following example, Perl compiles the pattern /\bmagic_word\b/ only once, since it is a constant pattern. Perl reuses the compiled form again and again during run time:

# count occurrences of magic_word in @big_long_list
foreach (@big_long_list) {
  $count += /\bmagic_word\b/;
}


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial