The stupid question is the question not asked | |
PerlMonks |
Re: Constructive Criticism for My First Perl Programby wog (Curate) |
on Sep 13, 2001 at 02:28 UTC ( [id://112045]=note: print w/replies, xml ) | Need Help?? |
You should fix that problem. And the other compliation error that will appear after you fix that one. Please, test your code before showing it to us. That said, don't make external calls to date like that, try Date::Format, or strftime from the POSIX module (use POSIX qw(strftime); my $today = strftime('%d%b%y',localtime);). Doing that should make your code more portable. Also, Mail::Send is probably a better thing to use then sendmail directly (since some systems don't have sendmail, of course.) That may also make your code more portable. I would also strongly reccommend you indent your subroutines consistently. (Personally I prefer that all subroutines be indented, but I can see a good reason to not do that, in some cases.) update: Looking at your code with more detail I see this:
This is MUCH better written as a loop. For example:
And that's still terribly written, too. You should try to make your subroutines be independent of each other -- avoid global variables. update2: (... pass things as arguments to subroutines instead, or use OO if that is more appropriate.) Another potential problem I see is this:
The problem with this is that regex metacharacters will be interperated in the IP address, so the .s in the IP address will match any character. For example, if the IP address were 1.2.4.8 then lines of the logfile for the IP address 162.4.83.1 would match that. You might be better of using something like $_ =~ /\Q$ip\E/, or index($_, $ip) != -1. On this issue of your regex for extracting the domain, etc from the email, note that there are many valid emails that your regex won't match (search for a node on e-mail validation to see why). Consider using Mail::Address instead of a regex.
In Section
Seekers of Perl Wisdom
|
|