Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Why was it neccessary to pass a DBI handler by reference?

by Abigail-II (Bishop)
on Jan 29, 2004 at 23:15 UTC ( [id://325074]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Why was it neccessary to pass a DBI handler by reference?
in thread Why was it neccessary to pass a DBI handler by reference?

Considering that arrays and hashes can only contain scalars, how do you construct multi-dimensional datastructures?

The first paragraph of the description section of 'man perlref' says Any scalar may hold a hard reference. (Hard reference is used here to indicate it's not a soft- or symbolic reference). If references aren't scalars, what does that sentence mean?

$ perl -MDevel::Peek -wle 'my $dbh = "foo"; Dump \$dbh' SV = RV(0x8194068) at 0x817cca0 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x817cd54 SV = PV(0x817cf90) at 0x817cd54 REFCNT = 2 FLAGS = (PADBUSY,PADMY,POK,pPOK) PV = 0x818f688 "foo"\0 CUR = 3 LEN = 4
Devel::Peek thinks that \$dbh is an SV, which stands for scalar value.

So, what is it that makes you think that references aren't scalars? Do you have documentation quotes, code fragments, or pointers to the source that back up your claim?

Abigail

Replies are listed 'Best First'.
Re: Re: Why was it neccessary to pass a DBI handler by reference?
by MCS (Monk) on Jan 30, 2004 at 06:29 UTC

    Sorry, my understanding was incorrect. The way I (incorrectly) understood it was that $y was a scalar representation of the reference \$x. (In the example: "my $y = \$x;") I then thought that when you dereferenced it, it converted it back into a reference.

    Of course, I guess this is sortof how it works, in that \$x must figure out the address of x and return it so in a way it almost acts like a function. So \$x is basically a function with the parameter $x that returns the address of $x. (as a scalar of course) But then again \ isn't really a function, I imagine it interprets whatever follows it at runtime. However, I'm not about to start digging around the perl code to see exactly how it works.

      Of course, I guess this is sortof how it works, in that \$x must figure out the address of x and return it so in a way it almost acts like a function.
      No, this is Perl, not C. A reference is a reference, and not a pointer. There are pointers involved in the internals, but pointers are used for other scalar types as well.

      Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://325074]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2024-06-14 12:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.