passing dbh

2005-01-10 Thread Alec Brecher
I am trying to figure out the most efficient method of passing around a live dbh when calling a subs. I have embedded a dbh into an object: $obj-{dbh} and would like to pass to it to other functions for reuse. Should I call: foo( $obj-{dbh} ); or: foo( \$obj-{dbh} ); or something else? Does the

Re: passing dbh

2005-01-10 Thread David Goodman
call: foo( $obj-{dbh} ); First of all, the dbh is already a reference. There is no point in creating another one. Secondly, when you pass variables as arguments to a perl function, it actually operates on the variable. If you modify the variable, the variable is modified in the callers context.

RE: passing dbh

2005-01-10 Thread CAMPBELL, BRIAN D (BRIAN)
Message- From: Alec Brecher [mailto:[EMAIL PROTECTED] Sent: Monday, January 10, 2005 8:35 AM To: Dbi-Users Subject: passing dbh I am trying to figure out the most efficient method of passing around a live dbh when calling a subs. I have embedded a dbh into an object: $obj-{dbh} and would like

Re: passing dbh

2005-01-10 Thread David
On Mon, Jan 10, 2005 at 10:35:16AM -0500, Alec Brecher wrote: I am trying to figure out the most efficient method of passing around a live dbh when calling a subs. Since Perl passes sub arguments by reference, it is already fairly efficient. Plus, it is unlikely the overhead of passing a

RE: passing dbh

2005-01-10 Thread Alec Brecher
the entire object: bar( $obj ); not just the dbh. Thank you again. -Alec -Original Message- From: David [mailto:[EMAIL PROTECTED] Sent: Monday, January 10, 2005 11:10 AM To: Dbi-Users Subject: Re: passing dbh On Mon, Jan 10, 2005 at 10:35:16AM -0500, Alec Brecher wrote: I am trying

RE: passing dbh

2005-01-10 Thread Jeffrey . Seger
: Subject:RE: passing dbh Thanks to all who replied. My biggest concern was that copying the dbh meant that a new connection would be created. And somehow had the impression that arguements were passed by value not reference. The reason for embedding the dbh into the obj: $obj-{dbh

Re: passing dbh

2005-01-10 Thread David
On Mon, Jan 10, 2005 at 12:28:44PM -0500, [EMAIL PROTECTED] wrote: I hate confusion, so I went to the source: perldoc perlsub, and here is what it had to say: The Perl model for function call and return values is simple: all functions are passed as parameters one single flat list

Re: passing dbh

2005-01-10 Thread Hardy Merrill
This thread is getting a bit OT, but... David [EMAIL PROTECTED] 01/10/05 12:36PM On Mon, Jan 10, 2005 at 12:28:44PM -0500, [EMAIL PROTECTED] wrote: Passing arguments explicitly by reference is only useful is you want to pass an array or hash as a single entity. HM I respectfully disagree :)

Re: passing dbh

2005-01-10 Thread Jeffrey . Seger
Damn I hate being publicly wrong, but you're right. #!/usr/bin/perl -w use strict; my $a = 1; foo($a); print $a\n; sub foo { $_[0] = 2; } prints '2'. It's shifting them off that list that creates the copy I am used to working with. But it still remains true that passing $dbh is safe