http://qs321.pair.com?node_id=1206868


in reply to Re^2: searching in large file
in thread searching in large file

Hello sabas

To answer your questions.

  1. yes
  2. In Perl, these metacharacters need to be escaped if they are to be matched literally \ | ( ) [ { ^ $ * + ? . (also called the dirty dozen) By using \Q ... \E, you escape any possible metacharacters in the variable being used for the regular expression - in this case $_
  3. He is compiling the regular expression $search_expression From Regexp Quote Like Operators the reason is Precompilation of the pattern into an internal representation at the moment of qr() avoids the need to recompile the pattern every time a match /$pat/ is attempted So, this avoids compiling the regular expression each time it is encountered in the while loop below next unless m/$search_expression/;
  4. Go to the top of the while loop and get the next line unless the regular expression matches this line. This skips the lines of code below if true.