Mazhar wrote:
> Folks,

Hello,

> I am a software developer and I have a written a script which will read the
> configuration like to address, subject of the mail and the threshold value.
> After reading the three values from the config file i will query the
> database and the result of the query i am genearting a report and the same
> report i am sending the same as mail. This script works fine at my end, if i
> execute the same at different machine situated at different place. I am not
> getting the values, A small part of program i will send it you guys just
> help me,
> 
> PGM :
> #!/usr/bin/perl
> #

The next two lines should be:

use warnings;
use strict;


> use DBI;
> 
> #
> # Variables
> #
> $mysql_db_host = "Host"; # MySQL Host
> $mysql_db_port = "Port"; # MySQL Port
> $mysql_db_user = "username"; # MySQL User
> $mysql_db_pass = ""; # MySQL Pass
> $config_file = "/u01/pix/config.txt"; # Config File
> 
> $date=`date +%Y%m%d`;
> $date=~s/\n//g;
> $tHr=`date +%H`;
> $tM=`date +%M`;
> $tS=`date +%S`;
> $temp=$tM-30;
> if ($temp<0)
> {
> $tHr=$tHr-1;
> $tM=60-$tM;
> }
> else
> {
> $tM=$tM-30;
> }
> $tDate=`date +%Y'-'%m'-'%d`;
> $tFrom=join "",$tDate," ",$tHr,":",$tM,":",$tS;
> $tFrom =~ s/\n+//g;
> $tTo=`date +%Y'-'%m'-'%d' '%H':'%M':'%S`;

You are calling an external program six times! - to do something that you
could do with the tools that perl provides.

Your 'calculation' produces a time difference of 30 minutes only about 52.5%
of the time and a positive difference between 2 and 58 minutes for about 45.5%
of the time and a negative difference between -118 and -62 minutes the rest of
the time.  I assume that you actually want the $tFrom variable to be 30
minutes before the $tTo variable so you could do it in perl like this:

use POSIX 'strftime';

my $thirty_minutes = 30 * 60;

my $tTo = strftime '%Y-%m-%d %H:%M:%S', localtime;

my $tFrom = strftime '%Y-%m-%d %H:%M:%S', localtime time - $thirty_minutes;


> open(FILE,"<$config_file");

You should *ALWAYS* verify that the file was opened correctly!

open FILE, '<', $config_file or die "Cannot open $config_file: $!";


> while (<FILE>) {
> $line = $_;

Why copy the contents of $_?  Why not just:

while ( my $line = <FILE> ) {


> if ($line =~ /(.*)To :(.*)/)
> {
> ($tmp,$ToMail)=split("To :",$line);

You are doing way too much work:

    if ( $line =~ /To :(.*)/ ) {
        $ToMail = $1;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to