l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2001 Dec 30 17:04

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] A question of perl style
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] A question of perl style

yea if you just pass in $dbh you are passing in a reference. and it is not
a big mem copy or anything inefficient like passing in a whole array
instead of a ref to an array or something.

you can always do a ref() on something to find out what it is.

[dale@eng database]$ perldoc -f ref
=item ref EXPR

=item ref

Returns a TRUE value if EXPR is a reference, FALSE otherwise.  If EXPR
is not specified, C<$_> will be used.  The value returned depends on the
type of thing the reference is a reference to.
Builtin types include:


If the referenced object has been blessed into a package, then that
name is returned instead.  You can think of C<ref()> as a C<typeof()>

    if (ref($r) eq "HASH") {
        print "r is a reference to a hash.\n";
    unless (ref($r)) {
        print "r is not a reference at all.\n";
    if (UNIVERSAL::isa($r, "HASH")) {  # for subclassing
        print "r is a reference to something that isa hash.\n";

See also L<perlref>.

On Mon, 30 Apr 2001, Jay Strauss wrote:

> Lets say I have a database handle object, $dbh.  Now I
> want to pass it to another subroutine like:
> backup(dbh=>$dbh);
> sub backup
> {
>    my (%arg) = @_;
>    my $sth = $arg{"dbh"}->prepare(some SQL);
>    my $rc  = $sth->execute();
> }
> Now this works, but shouldn't I be passing a reference
> to the object, and then unreferencing it in the sub
> routine?
> I tried:
> backup (dbh=>\$dbh);
> sub backup
> {
>    my (%arg) = @_;
>    my $dbh = \$arg{"dbh"};
>    my $sth = $dbh->prepare(some SQL);
>    my $rc  = $sth->execute();
> }
> But that didn't work.  Maybe this is all stupid
> because I think $dbh is just a pointer to an object,
> and so passing by value just gives me another pointer
> to an object.
> Jay
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/

Dale Bewley - Bewley Internet Solutions Inc. http://bewley.net/

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.