|
|
| We don't bite newbies here... much | |
| PerlMonks |
perlfunc:studyby gods (Initiate) |
| on Aug 24, 1999 at 22:43 UTC ( [id://364]=perlfunc: print w/replies, xml ) | Need Help?? |
studySee the current Perl documentation for study. Here is our local, out-dated (pre-5.6) version: ![]() study - optimize input data for repeated searches
![]() study SCALAR study
![]()
Takes extra time to study
SCALAR ( For example, here is a loop that inserts index producing entries before any line containing a certain pattern:
while (<>) {
study;
print ".IX foo\n" if /\bfoo\b/;
print ".IX bar\n" if /\bbar\b/;
print ".IX blurfl\n" if /\bblurfl\b/;
# ...
print;
}
In searching for
Note that if you have to look for strings that you don't know till runtime,
you can build an entire loop as a string and eval() that to avoid recompiling all your patterns all the time. Together with
undefining
$search = 'while (<>) { study;';
foreach $word (@words) {
$search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n";
}
$search .= "}";
@ARGV = @files;
undef $/;
eval $search; # this screams
$/ = "\n"; # put back to normal input delimiter
foreach $file (sort keys(%seen)) {
print $file, "\n";
}
|
|