RE: perl problem...
by =?iso-8859-1?Q?Burak_G=FCrsoy?= other posts by this author
Aug 1 2004 5:29PM messages near this date
view in the new Beta List Site
perl problem...
|
Re: Perl threads crash perl
DBI::db=HASH(0x81a1bbc) thing is the stringified version of your $dbh. And
you pass the *STRING* value "DBI::db=HASH(0x81a1bbc)" to your other .pl file
not the dbi handle/object and this is *NOT* the same value like you think.
And as far as I know you can't do that kind of call. If you need to pass
your object to another program via system calls, first serialize it with
Data::Dumper/Storable/etc and then de-serialize it from another app... or
use use()/require() to load the db connection code
What you are currently doing (or what perl.exe thinks what you are doing) is
this:
$class = "DBI::db=HASH(0x81a1bbc)";
$class-> prepare(...)
-----Original Message-----
From: perl-win32-users-bounces@[...].com
[mailto:perl-win32-users-bounces@[...].com]On Behalf Of bruce
Sent: Sunday, August 01, 2004 6:59 PM
To: perl-win32-users@[...].com
Subject: perl problem...
hi...
this continues the hashing question that i asked about...
i have a parent test app that sets up an initial 'link/handle' to a mysql
db. i want to be able to "pass" this handle to a child app via an
exec/system shell command, where the child app will be able to use the
'handle/link' created in the parent to perfrom the db functions..
the question, how do i accomplish this?
test parent app
-------------------------------------------------------
use strict;
use DBI;
require ('mysql.inc');
# $ARGV is a perl var.. no need to declare
my $arg = $ARGV[0];
# setup the db connection process...(global)
# in case we need to do a rollback at some time...
my ($sth, $rv)="";
my $dbh = "";
print "open db\n";
$dbh = open_dbi();
# at this point, dbh should be the connection id...
print "dbh = ".$dbh."\n";
system 'perl', 'aaa.pl', $dbh;
test child app
-------------------------------------------------------
#
#use strict;
use DBI;
require ('mysql.inc');
# $ARGV is a perl var.. no need to declare
my $arg = $ARGV[0];
print "aaa arg = ".$arg."\n";
# setup the db connection process...(global)
# in case we need to do a rollback at some time...
my ($sth, $rv)="";
my $dbh = $arg;
# at this point, dbh should be the connection id...
print "aaa dbh = ".$dbh."\n";
# make a test call to the db to verify that it works...
#
my $test_sql = 'select * from stateTBL';
print "sql = $test_sql\n";
$sth = $dbh-> prepare($test_sql);
...
now, at this point, i assumed that the app would be ok. in fact, displaying
the '$arg' value and comparing it to the '$dbh' value in the parent app
appeared to give the same value, as seen when i ran the test, and viewed the
output. however, something is going on that i don't fully understand...
the test output is...:
[root@lserver2 test]# perl mysql_client.pl
open db
dbh = DBI::db=HASH(0x81a1bbc) <<<<<<<<<<<<<<<< parent app....
dbharray = ARRAY(0x80fbd3c)
aaa arg = DBI::db=HASH(0x81a1bbc) <<<<<<<<<<<<< child app.....
aaa _db = DBI::db=HASH(0x81a1bbc)
aaa dbh = DBI::db=HASH(0x81a1bbc)
sql = select * from stateTBL
Can't locate object method "prepare" via package "DBI::db=HASH(0x81a1bbc)"
(perhaps you forgot to load "DBI::db=HASH(0x81a1bbc)"?) at aaa.pl line 50.
sql = select * from stateTBL
so, as you can see, it appears that the apps have the same value, and that
we should be ok... but the error statement suggests that perl is doing
something with the value, that suggests i have totally screwed things up, or
that i can't simply "pass" the var from the parent to the child as i thought
i could!!!!!
any ideas/suggestions/comments/etc on how one should actually pass vars from
a parent to a child..????
thanks
-bruce
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
bruce
=?iso-8859-1?Q?Burak_G=FCrsoy?=
|