Rob Dixon wrote:
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



Oops
I am sorry to have hurt you. But this was not cut pasted from my actual code. I cannot paste my 250 line script here so I jus wrote a hapazard , relevant replica of what I did.


Thanks anyway , I do use strict ( not warnings , irritates me when perl tells me use of unitialized var when I meants it to be so )

And in my real script I have @array as something more meaningful
But doesnt work anyway

I just have changed the logic
I am using /mi always and put only regex in the array and am looping thru the array


Ram




-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to