Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Okay, be kind to a newbie here...
I'm wanting to build an alternation at run-time to filter the contents of a log file. I'm not setting the appropriate switch to the regular expression. The code is below:
#!/usr/bin/perl use strict; # create alternation my @list; while (<DATA>) { chomp; push @list, $_; } my $regex = '[' . join('|', @list) . ']'; my $s = 'huey'; print "match:\t$s\n" if $s =~ m/\Q$regex/; __DATA__ huey dewey louie
Thoughts? Can you help educate the less fortunate? Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: creating a regular expression's alternation dynamically?
by Zaxo (Archbishop) on Aug 06, 2004 at 14:58 UTC | |
|
Re: creating a regular expression's alternation dynamically?
by mifflin (Curate) on Aug 06, 2004 at 14:26 UTC | |
by integral (Hermit) on Aug 06, 2004 at 14:39 UTC | |
by mifflin (Curate) on Aug 06, 2004 at 17:27 UTC | |
|
Re: creating a regular expression's alternation dynamically?
by davido (Cardinal) on Aug 06, 2004 at 15:14 UTC | |
|
Re: creating a regular expression's alternation dynamically?
by ysth (Canon) on Aug 06, 2004 at 18:21 UTC |