>>>>> "David" == David Jacobowitz <[EMAIL PROTECTED]> writes:
David> I have constructed an array using my table field names and
David> trying to pass that array in the select statement.
David> @inc_re = ( Hotels, Asian_Real_Estate, Smart_Buildings, Real_Estate,
David> Senior_Living_Homes );
This isn't very good Perl, unfortunately. Perl will eventually resort
to parsing these as strings, but a better way to write this is
probably either:
| @inc_re = ( 'Hotels',
| 'Asian_Real_Estate',
| 'Smart_Buildings',
| 'Real_Estate',
| 'Senior_Living_Homes' );
Another way to do this, which I actually prefer, is to use qw// (see
perlop):
| @inc_re = qw( Hotels
| Asian_Real_Estate
| Smart_Buildings
| Real_Estate
| Senior_Living_Homes );
David> $quary = "SELECT @inc_re FROM incu_real_estate LIMIT 1";
@array_name within a string is expanded with spaces between elements,
not commas (see perlop). The expansion for
"@array"
Is the same as though you had done:
join($", @array)
Where $" is a special variable (perlvar).
So, since we want commas, we can either set $" (which I sometimes do),
or join with commas explicitly.
| $query = "SELECT " . join(', ', @inc_re) .
| " FROM incu_real_estate" .
| " LIMIT 1";
David> But I am getting following error.
David> $./test.pl
David> In string, @inc_sf now must be written as \@inc_sf at ./test.pl
David> line 15, near "SELECT @inc_sf"
This is a standard message; you use an array name that hadn't been
declared or used yet (@inc_sf, when you assigned @inc_re above), and
it told you that you should always escape your at signs if you want
them to appear literally in the output. (perldiag).
David> I have added a \ infront of the array but the quary doesn't
David> return any thing.
An invaluable aid here is to print out the full SQL string you are
trying to send to your database.
Putting together what I've said here, I'd try something like this:
| my @inc_re = qw( Hotels
| Asian_Real_Estate
| Smart_Buildings
| Real_Estate
| Senior_Living_Homes );
|
| my $query = "SELECT " . join(', ', @inc_re) .
| " FROM incu_real_estate" .
| " LIMIT 1";
|
| print STDERR "\$query=\"$query\"\n";
|
| my $sth = $dbh->prepare($query)
| or die "prepare $query: $DBI::errstr";
| $sth->execute()
| or die "execute $query: $DBI::errstr";
And so on.
t.