Start with the basic idea that he's using a hash slice:
@column{'one', 'two', 'three'} is valid Perl syntax, meaning
the slice of hash %column, containing the elements $column{'one'},
$column{'two'}, and $column{'three'}. In list context that would
look like this:
{$column{'one'}, $column{'two'}, $column{'three'})
The qw(one two three four five) just allows him to not have to write
it all out -- that expands on its own to:
'one', 'two', 'three', 'four', 'five'
So expanding things together it's:
@column{'one', 'two', 'three', 'four', 'five'};
Which is (using the same rationale as that used above):
($column{'one'}, $column{'two'}, $column{'three'}, $column{'four'},
$column{'five'})
Putting \ in front of a list is Perl shorthand for taking a reference to
each element in the list. So adding the backslash makes it equvalent to
saying:
\$column{'one'}, \$column{'two'}, \$column{'three'}, \$column{'four'},
\$column{'five'}
That's exactly the type of arg list bind_columns() wants.
Pretty cool. Pretty Perl. 8-)
> -----Original Message-----
> From: Thomas A. Lowery [mailto:[EMAIL PROTECTED]]
> Sent: Friday, March 09, 2001 10:56 PM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: Re: Reusable code for binding columns.
>
>
> OK Randal, how does this work? I put it in code and see it
> WORKS, but my
> brains hurts trying to understand it.
>
> > $rc = $sth->bind_columns(\@column{qw(one two three four five)});
>
> Tom
>
> On Wed, Mar 07, 2001 at 11:46:07PM -0800, Randal L. Schwartz wrote:
> >
> > This is weird, but it works:
> >
> > Now $column{one} is the first column, and $column{two} is the second
> > column. Very cool, and much faster than the fetchrow_hashref, since
> > we aren't rebuilding the hash each time... instead the fetch goes
> > right into the existing scalars which were bound.
>
> --
> Thomas A. Lowery [EMAIL PROTECTED]
> http://tlowery.hypermart.net
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>