Ramprasad wrote: > > I have an array of regular exps of which I want to match any of them > in a string. How can I do this without eval. > > for eg. > > @array = ( > '/^to: myprog/mi', > '/^from: [EMAIL PROTECTED]/mi' > ); > > $STRING = read_mail_header(...); > > > foreach (@array) { > if($STRING=~ $_ ) { # This does not work > # FOUND > ............. > } > } > > > # NOTFOUND > [snip]
Hi Ram. First of all use strict; use warnings; and preferably use lower case for variables. Next, there's a module on CPAN to do exactly this. Someone remind me of the name please? Thirdly, do you really need the /m and /i modifiers? Elastic code is prone to bugs! Finally, if it's an array of regexes then say so in your code. Then it will work. Look at this. HTH, Rob use strict; use warnings; my @array = ( qr'^to: myprog'mi, qr'^from: [EMAIL PROTECTED]'mi ); my $str = 'To: myprog with trailing text'; foreach (@array) { print "found\n" if $str =~ $_ } OUTPUT found -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]