Hi All i have created the script which calls method from other script lib and while executing i get and error Can't call method "prepare" on an undefined value at /home/patriat/sourcescr/input/lib/patriat_lib.pl line 226. -
# conect to database
-
$dbh = DBI->connect( $ENV{ORACLE_SID}, $ENV{ORAUSER}, $ENV{ORAPASSWD}, 'Oracle');
-
-
################################ {
-
-
# inserting into job_audit table
-
print PLOG &now, " : Inserting into the JOB_AUDIT Table\n";
-
&insert_job_audit($opt_p, $COMPLETE, $COHESION, $timestamp, $cohfileout, $LAST_FILE_PROCESSED);
-
-
print PLOG &now, " : inserted into the JOB_AUDIT Table \n";
-
-
$dbh->disconnect;
-
another script is -
#################################
-
#Insert into JOB_AUDIT table
-
#################################
-
-
sub insert_job_audit {
-
-
local($l_opt_p, $l_COMPLETE, $l_COHESION, $l_timestamp, $l_cohfileout, $l_LAST_FILE_PROCESSED) = @_;
-
$SQL = "
-
INSERT INTO JOB_AUDIT@TO_P1DBDEV ('JOB_NAME','STATUS','SENT_TO','RUN_DATE','EXTRACT_FILE_NAME','FILE_SEQ_NO')
-
VALUES (?,?,?,?,?,?)";
-
-
$csr4 = $dbh->prepare($SQL);
-
-
if ($DBI::errstr) {
-
&log_error($SQL,$DBI::errstr,$YES);
-
}
-
-
-
$csr4->execute ($l_opt_p, $l_COMPLETE, $l_COHESION, $l_timestamp, $l_cohfileout, $l_LAST_FILE_PROCESSED);
-
-
if ($DBI::errstr) {
-
&log_error($SQL,$DBI::errstr,$YES);
-
}
-
-
$dbh->commit;
-
$csr4->finish();
-
printf STDLOG ("values inserted in the JOB_AUDIT table\n");
-
}
-
11 14465 KevinADC 4,059
Recognized Expert Specialist
thisis the only line I see with "prepre" in it:
$csr4 = $dbh->prepare($SQL);
so $dbh is undefined when you try and call the prepare method. You have to determine why it is undefined.
i defined it but again its giving same error. but i dont think we need to define the handle
numberwhun 3,509
Recognized Expert Moderator Specialist
You definitely have to determine why that value isn't being set and I think you should set some print statements after variable declarations to ensure they are being set.
Another thing, you definitely aren't using "use strict" because you don't have 'my' in front of your initial declarations. This makes me wonder if you are using "use warnings". They both will help you to avoid the silly errors and allow people to trouble shoot the actual issues in your code, not the silly stuff.
Regards,
Jeff
KevinADC 4,059
Recognized Expert Specialist
i defined it but again its giving same error. but i dont think we need to define the handle
Well, the error message clearly tells you that $dbh needs to be defined and needs to be defined properly. How did you 'define' it?
Note what Jeff said above too about using "strict" and warnings".
hi,
i have use strict and defined the dbh too. can there is some other problem with perl module as i am new to perl. still getting error as
Can't call method "prepare" on an undefined value at /home/patriat/sourcescr/input/lib/patriat_lib.pl line 226.
$csr4 = $dbh->prepare($SQL);
numberwhun 3,509
Recognized Expert Moderator Specialist
Since we cannot see the whole of your code, we are only going to be able to speculate what is going on.
I wonder, do you previously in your code have the line to assign the new() object to $dbh?
ie: -
my $dbh = new(DBI..... );
-
Just curious.
Regards,
Jeff
miller 1,089
Recognized Expert Top Contributor -
# conect to database
-
$dbh = DBI->connect( $ENV{ORACLE_SID}, $ENV{ORAUSER}, $ENV{ORAPASSWD}, 'Oracle');
-
-
...
-
-
&insert_job_audit($opt_p, $COMPLETE, $COHESION, $timestamp, $cohfileout, $LAST_FILE_PROCESSED);
-
another script is -
#################################
-
#Insert into JOB_AUDIT table
-
#################################
-
-
sub insert_job_audit {
-
...
-
$csr4 = $dbh->prepare($SQL);
-
}
-
You have defined $dbh in your primary script, but it is not defined in your secondary script in which the sub insert_job_audit is located. I suggest that you pass the $dbh as the first parameter to the function so that it is defined.
Also, do not use local for subroutine parameters. In fact, unless there is a specific reason why you need it, you should never use local. Instead use my
And I second all of the things that Jeff and Kevin stated about including "use strict;" at the top of all of your scripts. If you really had included it, then an error should have been thrown during compile time instead of at runtime when the prepare statement is reached.
- Miller
Since we cannot see the whole of your code, we are only going to be able to speculate what is going on.
I wonder, do you previously in your code have the line to assign the new() object to $dbh?
ie: -
my $dbh = new(DBI..... );
-
Just curious.
Regards,
Jeff
nopes i dint use new()
still i am not able to resolve my problem.
now its saying as
Can't locate strict.pm in @INC (@INC contains: /opt/perl5.6.1/lib/site_perl/5.6.1 /opt/perl5.6.1/lib/5.6.1 /opt/perl5.6.1/lib/5.6.1/PA-RISC2.0 /opt/perl5.6.1/lib/site_perl/5.6.1/PA-RISC2.0 /home/patriat/sourcescr/input/lib /project/hpunix64/902/APACHE/src/pdc_perl/bin/HPUX/Opt/lib/5.00503/PA-RISC2.0 /project/hpunix64/902/APACHE/src/pdc_perl/bin/HPUX/Opt/lib/5.00503 /project/hpunix64/902/APACHE/src/pdc_perl/bin/HPUX/Opt/lib/site_perl/5.005/PA-RISC2.0 /project/hpunix64/902/APACHE/src/pdc_perl/bin/HPUX/Opt/lib/site_perl/5.005 .) at /home/patriat/sourcescr/output/src/ras2coh.pl line 21.
BEGIN failed--compilation aborted at /home/patriat/sourcescr/output/src/ras2coh.pl line 21.
numberwhun 3,509
Recognized Expert Moderator Specialist
That is just weird that you are getting that. Strict is part of the base installation of Perl. If it is not installed, then you are going to have to go to CPAN and install the strict module from there. That should clear up that error.
Regards,
Jeff
KevinADC 4,059
Recognized Expert Specialist
lets see the first 30 or so lines of ras2coh.pl
if "strict" really is not there your version of perl is no good for reasons unkown. It is long overdue for upgrade anyway since perl 5.6 is very old.
-
#
-
# Description:
-
#
-
# ftp extract file to cohesion and compress the extract file.
-
#
-
# This script was created to overcome OS problems encountered when
-
# this code was included in the ras_attr_extract.pl script. The
-
# error encountered was "Not enough space" when the extract files
-
# grew in size.
-
#
-
# Change history:
-
#
-
# Manu Kodiyan 04/05/04 Created
-
#
-
#
-
#
-
unshift (@INC, "/home/patriat/sourcescr/input/lib");
-
require 'getopts.pl';
-
require '/home/patriat/sourcescr/input/lib/patriat_lib.pl';
-
use strict;
-
use Getopt::Std;
-
use vars qw($opt_p $opt_d);
-
use File::Copy;
-
require "comfunc.pl";
-
use DBI;
-
use Data::Dumper;
-
getopts('p:d:');
-
-
my $emailmsg;
-
my $loglines;
-
my $raspath = "/home/patriat/data/ras/";
-
my $cohpath = "/home/patriat/data/ras/";
-
my $backup = "/home/patriat/backup/ras/";
-
my $weblink = "/home/patriat/sourcescr/web_pages/html/onlinedoc/";
-
my $total = 0;
-
my ($timestamp) = timestamp ();
-
my $LAST_FILE_PROCESSED= 0;
-
my $COMPLETE = "COMPLETE";
-
my $COHESION = "COHESION";
-
-
my ($subject, $content, $cc);
-
$subject = "PROGRAM $opt_p";
-
$cc = $ENV{PROD_SUPPORT};
-
my ($dbh);
-
-
-
###################################################################################
-
# conect to database
-
#################################################################################
-
-
my ($subject, $content, $cc);
-
$subject = "PROGRAM $opt_p";
-
$cc = $ENV{PROD_SUPPORT};
-
my ($dbh);
-
-
-
-
-
-
-
if (!$opt_d || !$opt_p)
-
{
-
$emailmsg = "ftp to cohesion script not configured properly\n\n" .
-
"USAGE ras2coh.pl -p <calling program> -d <extract file>\n";
-
$subject .= " -FAILURE";
-
sendMail ($subject, $emailmsg, $cc);
-
exit 1;
-
}
-
-
-
my $TMP_LOG = "/home/patriat/log/ras/log.tmp";
-
-
my $PEX_LOG = "/home/patriat/log/ras/${opt_d}";
-
$PEX_LOG =~ s/csv/log/;
-
-
my $PEX_LOG_FTP = $PEX_LOG;
-
$PEX_LOG_FTP =~ s/\.log/_ftp\.log/;
-
-
open ( PLOG, ">>$PEX_LOG" );
-
print PLOG "\n";
-
print PLOG `date`;
-
print PLOG "Preparing to ftp ras $opt_d file to cohesion\n\n";
-
-
-
my ($cohfileout) = $opt_d;
-
-
# rename extension to .dat fro Cohesion
-
$cohfileout =~ s/csv$/dat/;
-
-
-
$total = `wc -l ${raspath}$opt_d`;
-
$total =~ /^(\d+)/;
-
$total = $1 - 1; # -1 for the header
-
-
rename $raspath . $opt_d, $cohpath . $cohfileout;
-
-
my ($coherrstr, $cohcmd, $coherrstr);
-
-
#
-
# ftp to the cohesion drop box
-
#
-
#$cohcmd = "/home/patriat/sourcescr/output/src/ftp2coh.sh $cohfileout >$PEX_LOG_FTP 2>&1";
-
#$coherrstr = system($cohcmd);
-
-
if ($coherrstr) {
-
open (TMP, "<$PEX_LOG_FTP");
-
$loglines = '';
-
while (<TMP>) {
-
$loglines = $loglines . $_;
-
}
-
close (TMP);
-
# some error occured in the ftp script
-
$emailmsg = "Error during ftp of $cohfileout extract to cohesion. $loglines\n";
-
print PLOG $emailmsg;
-
$subject .= " -FAILURE";
-
sendMail ($subject, $emailmsg, $cc);
-
exit 1;
-
}
-
-
print PLOG "DATA file $cohfileout (renamed extension) is Succesfully ftp-ed to Cohesion\n";
-
-
-
-
-
##############################################################################
-
# inserting into job_audit table
-
##############################################################################
-
-
print PLOG &now, " : Inserting into the JOB_AUDIT Table\n";
-
&insert_job_audit('$opt_p','$COMPLETE','$COHESION','$timestamp','$cohfileout','$LAST_FILE_PROCESSED');
-
-
print PLOG &now, " : inserted into the JOB_AUDIT Table \n";
-
-
###############################################################################
-
-
-
$dbh->disconnect;
-
-
# Move the file back and compress
-
rename $cohpath . $cohfileout, $raspath . $opt_d;
-
-
unlink ( $raspath. $opt_d . ".Z" );
-
my($command) = "compress ${raspath}$opt_d";
-
$coherrstr = system("$command >$TMP_LOG 2>&1");
-
if ( $coherrstr )
-
{
-
open (TMP, "<$TMP_LOG");
-
$loglines = '';
-
while (<TMP>) {
-
$loglines = $loglines . $_;
-
}
-
close (TMP);
-
$emailmsg = "Error when compressing $opt_d extract file\n. $loglines";
-
$subject .= " -FAILURE";
-
print PLOG $emailmsg;
-
sendMail ($subject, $emailmsg, $cc);
-
exit 1;
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Gene Mat |
last post by:
Hi, I'm trying to build a simple Perl program to get a list of
newsgroups. Here's what I have...
#!/opt/local/bin/perl
use Net::NNTP;
$nntp = Net::NNTP->new("nntp.perl.org",Debug,10);...
|
by: Asyn lordasyn |
last post by:
Ok... I know there is got to be something simple that I forgot, but I for the life of me can't find it. Please, for the sake of the wall I keep slamming my head into, any insight would be helpful.
...
|
by: David N |
last post by:
Hi All,
What is a best way to handle an undefined value object class that returned
from a function. I have a function that call the ADO.NET ExecuteScalar()
function and returns the object to...
|
by: Jean Stax |
last post by:
Hi !
I created a sample library project. In my second project I reference
this library
and make the following call, which returns "undefined value":
Type myType =...
|
by: Michael R |
last post by:
Here's one that's got me stumped...
I have a class with a member variable. I set it in a member method. In the
debugger, it shows up as <undefined> before AND AFTER it is set. However,...
| |
by: gmccammon |
last post by:
I am getting an error that says that I can't call method "prepare" on an undefined value!
Here is what I have as code.... I don't understand what is not defined.
# opens connection to Access...
|
by: pnsreee |
last post by:
Hi all,
Im trying to print ARRAY OF ARRAYS using following code.
for $i (0..10) {
print "\t } ] ,\n";
}
|
by: tgkprog |
last post by:
hi i'm trying to use Win32::IEAutomation to automate clickbank.com navigation and page saving
i can login and go to the https://www.clickbank.com/account/showTransactions.htm
page but cannot...
|
by: mithunmo |
last post by:
If I run the below program . I get the following error message
Can't call method "value" on an undefined value at C:/Perl/site/lib/Win32/IE/Mec
hanize.pm line 900.
Please let me know your...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |