in reply to Re^3: perl regular expressions
in thread perl regular expressions

Hello,The script is not working.I get the following error:

Global symbol "$string" requires explicit package name at map.pl line 13. Execution of map.pl aborted due to compilation errors. Use of uninitialized value $file in open at map.pl line 8. readline() on closed filehandle $fh at map.pl line 9.

I see that you have used @string but I see $string in die "Unable to find string: $string";

use strict; use warnings; find_string { my ($file, @strings) = @_; open my $fh, '<', $file; my $re = join "|", map quotemeta, @strings; while (<$fh>) { return 1 if /$re/; } die "Unable to find string: $string"; } find_string('prepos.config', "testing","link","100K");

Replies are listed 'Best First'.
Re^5: perl regular expressions
by kennethk (Abbot) on Jun 24, 2014 at 18:28 UTC
    Sorry, my oversight. The offensive line is the die, which should be updated to read (perhaps):
    die "Unable to find string(s): @strings";

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.