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
  • PrintPrint
Share this Page URL
Help

Chapter 3. Regular Expressions > Item 33. Watch out for the match variables

Item 33. Watch out for the match variables

The match variables ($`, $&, and $') impose a speed penalty on your Perl programs because they cause Perl to perform some extra bookkeeping. After a successful match, they represent the part of the string that comes before the match, the part that matched, and the part that follows the match, respectively:

'My cat is Buster Bean' =~ m/Buster/;

print <<"HERE";
 Prematch: $`
    match: $&
Postmatch: $'
HERE


  

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


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint