See below.
--
Mac :})
** I normally forward private database questions to the DBI mail lists. **
Give a hobbit a fish and he'll eat fish for a day.
Give a hobbit a ring and he'll eat fish for an age.
----- Original Message -----
From: "Matthew O. Persico" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, March 09, 2001 8:55 PM
Subject: Re: Reusable code for binding columns.
>. . .
> Personally, I think this is a perfect example of the "beauty" of Perl.
> Visually, \@column{qw(one two three four five)} LOOKS like a ref of a
> list. Bit, I don't think there IS such a thing.
>
> \@foobar IS a ref of an ARRAY.
> \%baba is a ref of a HASH.
> \(1,2,3,4) is a ref of a LIST. But what's the point of that? If you want
> an ARRAY ref, you can do [1,2,3,4]. If you want a hash ref, do
> \{1,2,3,4} (or, more clearly, \{1=>2,3=>4}). A ref of a LIST is
> ambiguous, as used in this context. Therefore, it can't be used that
> way. So, I guess, it was decided that defining this construct as
> converting a list to a list of refs would be useful and therefore, it
> was done.
Actually, \( 1, 2, 3, 4 ) distributes to ( \1, \2, \3, \4 ) which makes it
possible to send a bunch of different slices and scalars as references:
\( @hash{qw(one two three)}, @array[0 .. 4], $scal1, $scal2 ).
The most interesting way I've used that was when I was comparing two
identically structured tables in different instances:
$dbh -> {RaiseErrors} = 1;
my $cols = join ", ", (map{ "a.$_" } @keycols, @datacols),
map { "b.$_" } @datacols;
my $join = join " AND ", map { "a.$_ = b.$_ (+)" } @keycols;
my $compare = join " OR ", "b.$keycols[0] IS NULL",
map { "a.$_ != b.$_" } @datacols;
my $sth = $dbh -> prepare( join "\n",
"SELECT $cols",
" FROM tab1 a, tab2 b",
" WHERE $join AND ($compare)" );
$sth -> execute;
my ( @keyval, @dataval0, @dataval1 );
$sth -> bind_columns(
\( @keyval[0 .. $#keycols],
@dataval0[0 .. $#datacols], @dataval1[0 .. $#datacols] ) );
while ( $sth -> fetch ) {
# report rows with same keys that are missing or have different data
}
Multiply this by about 60 tables in 6 instances.