[ Please provide context when replying to a message. ]
dario wrote:
> Gunnar Hjalmarsson wrote:
>> dario wrote:
>>> How do I make this work!!!
>>
>> <fragmentary code snipped>
>>
>> Please post a _short_ but _complete_ program that illustrates the
>> problem you are having, just as is explained in the posting guidelines
>> for this group.
>> http://mail.augustmail.com/~tadmc/cl...uidelines.html
>
> Sorry about the previuos post, i hope this is better!
> I want to match regex stored in a file to a text in a variable $head_. It
> works in windows, but not on linux.
> Thanks!
> Dario
>
> Content of a file rule.spam is :
> new_1 head Subject: .*\.\.
>
> Code is:
>
> $head_ ="Subject: Get cheap v i a g r a ..... ";
>
> open (NWRULE, "<rule.spam");
> @new_rule=<NWRULE>;
> close (NWRULE);
>
> foreach $rule(@new_rule)
> {
> if($rule =~ /(\S+) (\S+) ([^\n]+)/)
> {
> $new_id=$1;
> $dio=$2;
> $reg=$3;
> }
> if($head_ =~ m/$reg/)
> {
> print "something\n";# it doesn't match
> }
> }
That's still not a complete program that people can copy, paste and run
as is suggested in the posting guidelines. The below code is (I
think...). Note: strictures and warnings enabled; input data provided
via the __DATA__ token.
OTOH, the below program prints the expected result, so you wouldn't have
needed to post it. But if you had written it, you could have concluded
that what's probably causing your program to fail is that the open()
statement fails. Applying one of 'the golden rules', i.e. checking the
return value of open(), would likely have told you that as well.
#!/usr/bin/perl
use strict;
use warnings;
my $head_ ="Subject: Get cheap v i a g r a ..... ";
while ( my $rule = <DATA> ) {
my ($new_id, $dio, $reg);
if ( $rule =~ /(\S+) (\S+) ([^\n]+)/ ) {
$new_id=$1;
$dio=$2;
$reg=$3;
}
if ( $head_ =~ m/$reg/ ) {
print "something\n";
}
}
__DATA__
new_1 head Subject: .*\.\.
--
Gunnar Hjalmarsson
Email:
http://www.gunnar.cc/cgi-bin/contact.pl