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
In reply to problem while searching for a pattern in a file by rajyalakshmi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |