I've put together a script to find a certain word if it occurs in a file directory. All together the script is doing what I hoped it would but I think I've come a cropper on the difference between array and list. I'm trying to put the $File::Find::name into a list so that one email is sent to the recipient rather than an email per time the pattern occurs (which is what is happening).
#!c:\perl\bin\perl.exe
use strict;
use warnings;
use File::Find;
use Net::SMTP;
my $mailserver_url = "foo";
my $from = 'foo@bar.com';
my $to = 'foo@bar.com';
my $subject = "CONNREFUSED lists";
my @result =();
undef $/;
find( sub
{
return if ($_ =~ /^\./);
return unless ($_ =~ /\.autodel/i);
stat $File::Find::name;
return if -d;
return unless -r;
open(FILE, "< $File::Find::name") or return;
my $string = <FILE>;
close (FILE);
return unless ($string =~ /\bCONNREFUSED\b/i);
my $smtp = Net::SMTP->new(Host => 'foo');
#Sending the message
$smtp->mail( $from );
$smtp->to( $to );
$smtp->data();
$smtp->datasend("To: $to\n");
$smtp->datasend("From: $from\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n"); # done with header
$smtp->datasend("$results\n");
$smtp->dataend();
$smtp->quit(); # all done. message sent.
},
'X:\\baz\\MAIN');
I did try setting up @results and using push $File::Find::name into it but it has failed to collect all the data together in one, rather it outputs 1, hence my wondering about the arrays and lists. I'd be grateful for some enlightenment on how to do this most effectively.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.