carcassonne has asked for the wisdom of the Perl Monks concerning the following question:
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; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: YARQ: multi_grep example in perlretut
by vkon (Curate) on Apr 08, 2006 at 13:53 UTC | |
by carcassonne (Pilgrim) on Apr 08, 2006 at 15:09 UTC | |
by strat (Canon) on Apr 09, 2006 at 09:44 UTC |