in reply to creating a regular expression's alternation dynamically?
Running the program...#!/usr/bin/perl use strict; # create alternation my @list; while (<DATA>) { chomp; push @list, $_; } my $regex = '^(' . join('|', @list) . ')$'; my $s = 'huey'; print "regex = $regex\n"; print "match:\t$1\n" if $s =~ m/$regex/; __DATA__ huey dewey louie
C:\Temp\test>perl test.pl regex = ^(huey|dewey|louie)$ match: huey
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: creating a regular expression's alternation dynamically?
by integral (Hermit) on Aug 06, 2004 at 14:39 UTC | |
by mifflin (Curate) on Aug 06, 2004 at 17:27 UTC |