in reply to perl regular expressions
or, if you're not really comfortable with join and map,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 { my ($file, @strings) = @_; open my $fh, '<', $file; while (<$fh>) { for my $string (@strings) { return 1 if /\Q$string/; } } die "Unable to find string: $string"; }
As a side note, it's usually good to wrap input in <code> tags as well, since HTML and perlmonks will collude to mangle your offering.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perl regular expressions
by iamsachin (Initiate) on Jun 23, 2014 at 23:25 UTC | |
by kennethk (Abbot) on Jun 23, 2014 at 23:30 UTC | |
by iamsachin (Initiate) on Jun 23, 2014 at 23:52 UTC | |
by kennethk (Abbot) on Jun 24, 2014 at 00:06 UTC | |
by tobyink (Canon) on Jun 24, 2014 at 00:55 UTC | |
by iamsachin (Initiate) on Jun 23, 2014 at 23:50 UTC | |
by iamsachin (Initiate) on Jun 24, 2014 at 14:04 UTC | |
by kennethk (Abbot) on Jun 24, 2014 at 18:28 UTC | |
by iamsachin (Initiate) on Jun 24, 2014 at 23:58 UTC | |
by kennethk (Abbot) on Jun 25, 2014 at 14:44 UTC |