in reply to store regex in hash

The lack of follow-up questions from salp suggests he or she has the "store the regex in a hash" part under control, but just in case:

>perl -wMstrict -le "my %rx = ( FOO => qr{ (?i) foo (?! bar) }xms, BAR => qr{ (?i) bar (?= (?-i) foo) }xms, ); ;; my $s = 'xxx FooBar fOO BaRFoO bArfoo bar yyy'; for my $type (keys %rx) { print qq{parsing $type-ish stuff with $rx{$type}}; while ($s =~ m{ ($rx{$type}) }xmsg) { print qq{ found a '$1'}; } } " parsing BAR-ish stuff with (?msx-i: (?i) bar (?= (?-i) foo) ) found a 'bAr' parsing FOO-ish stuff with (?msx-i: (?i) foo (?! bar) ) found a 'fOO' found a 'FoO' found a 'foo'

Replies are listed 'Best First'.
Re^2: store regex in hash
by salp (Novice) on Jul 04, 2011 at 03:11 UTC

    That works, thanks to everyone.

    PS: JavaFan is correct the code I posted would not compile I mistyped it in the post