This is Yet Another Regex Question. Yes indeed. The multi-grep example in perlretut works very fine... when not using 'use strict', that is. As soon as 'use strict' is specified, a flurry of the following appears:
Global symbol "$number" requires explicit package name [...] Global symbol "@regexp" requires explicit package name [...] Global symbol "$number" requires explicit package name [...]
Is it possible to make this code work with 'use strict', and if so, how ? - Thanks !
As a reference, here's how the code is called, and the code itself from perlretut:
Called like:
./multi_grep.pl 2 last for multi_grep.pl
The code (saved as multi_grep.pl):
$number = shift; $regexp[$_] = shift foreach (0..$number-1); @compiled = map qr/$_/, @regexp; while ($line = <>) { foreach $pattern (@compiled) { if ($line =~ /$pattern/) { print $line; last; } } }
In reply to YARQ: multi_grep example in perlretut by carcassonne
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |