Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Please suggest - Issue with comparing values
July 22, 2009, 12:36 pm
rate this thread
I have a perl file which is called from a ksh file. In this perl
script, I have to execute a procedure and get the output parameter.
this output paramtere(proces Date) needs to be compared with an input
parameter(run_date). If both dates are not same, I need to exit out of
the job. However, when I am trying to execute the procedure and
capture the value, it always returns 0. I am unable o capture this
date output and compare it with the input date. I am using DBI for
Below is the SAMPLE script. Can you please advise
$db_handle = &connectDB($server, $user, $password, $database);
my $date_cmp_sql ;
$date_cmp_sql = "
DECLARE \@ReportDate DATETIME,
SELECT \@ReportDate ='$report_date'
EXEC $db_name..GetPriorDate 1, \@ReportDate, \@ProcessDate output
$st = $db_handle->prepare("$date_cmp_sql") or die("Could not prepare
for SQL statement");
$st->execute() or die localtime(time). " ---Can't excute SQL
if ($err_str ne "")
print(" error \n");
my @RptFlag = ();
@RptFlag = $st->fetchrow_array() ;
my $RprtGenrFlag = $RptFlag;
print("RprtGenrFlag is $RprtGenrFlag \n\n");
##if ($Report_date eq "0")
$run_date = $RprtGenrFlag;
print("run_date is $run_date");
if($RprtGenrFlag eq $run_date)
print("two dates are equal \n");
print("dates are not equal \n");
&disconnectDB ($db_handle, $server);
Re: Please suggest - Issue with comparing values
Which procedure always returns 0? I see no
procedures/subroutines/functions in your code.
Does the SQL you execute return a date?
What is this? I dont see it used below.
You don't declare $db_handle. Also, you don't need the & on
sub calls, unless you need its effects, which you don't.
my $db_handle = connectDB( $server, $user, $password, $database );
What is this? Doesn't seem to be used.
Please use more care when constructing sample code.
Why declare variables then assign to them in a separate line?
You can make your code more compact and simultaneously more
readable by doing declaration and initialisation in one line:
my $date_cmp_sql = "... etc ...";
Did you print out $date_cmp_sql here to make sure it's what you expect?
Did you cut-and-paste that output into your database frontend to see if
you get the expected output?
Learn the art of debugging - it shouldn't be difficult, either with
print statements or with the perl debugger, to find the line of code
that's causing you problems.
again, do this in one line for clarity:
my $st = $db_handle->prepare( ... );
You've already checked the execute() for errors; I think this check of
errstr is unneccessary and possibly wrong. I am not a DBI expert
though. According to the DBI docs:
The errstr() method should not be used to test for errors, use err()
my @RptFlag = $st->fetchrow_array();
What are the contents of @RptFlag here?
print "\@RptFlag = " . Dumper \@RptFlag;
2 lines back You set $run_date = $RprtGenrFlag, now you compare
the two values - of course they will be equal!
As above, no '&' required:
disconnectDB( $db_handle, $server );
- » FAQ 6.19 Why does using $&, $`, or $' slow my program down?
- — Next thread in » PERL Discussions
- » FAQ 6.1 How can I hope to use regular expressions without creating illegible and unmaintai...
- — Previous thread in » PERL Discussions
- » ssh on command line: force using a group size (prime size) of 1024 (and no...
- — The site's Newest Thread. Posted in » Secure Shell Forum