rajyalakshmi has asked for the wisdom of the Perl Monks concerning the following question:
I have text file ,results.txt which has 2 things:
1.a newline character
2.a string "hello"
The following script of mine opens the results,reads each line .If it finds for the the string "hello", it sends a mail.If it does not find "hello". it does nothing.But the problem the mail is sent for both cases.Can you please figure whats the problem in the foll in script:
#!/usr/bin/perl use MIME::Lite; $pattern ='hello'; my $msg = MIME::Lite->new( From => 'rajyalakshmi.bangar@eternoinfotech.com', To => 'bangar.rajyalakshmi@gmail.com', Type => 'multipart/mixed', Subject => "Fetch issues as on $dateFile'", ); $msg->attach( Type => 'TEXT', Data => "Hi,Please find attachement for Fetch issues as on '$d +ateFile'", ); $msg->attach( Type => 'text', Path => 'results.txt', Filename => 'results.txt', ); #sysopen($FILE,$filepath,o_RDWR) or die "could find the file"; open FILE, "<results.txt" or die "Can't open results output file: $!"; while (my $line=<FILE>) { if($line=~m/\b$pattern/) { print " match"; $msg->send; } }
The mail is send for both foll conditions:
ie:ideally if match is found and the conditon is if($line!~m/\b$pattern/),the mail should not be sent
But if remove the new line character from the results.txt,the conditions work fine
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problem while searching for a pattern in a file
by cdarke (Prior) on Mar 24, 2010 at 09:05 UTC | |
|
Re: problem while searching for a pattern in a file
by kiruthika.bkite (Scribe) on Mar 24, 2010 at 08:18 UTC |