M
minjie
Hello,
I'm trying to do the following: to retrive all table names from a
database and display them on a web application, and when a user selects
one table, display all its fields and the corresponding values on the
web. I'm doing it in Perl (ver 5.8.0). I can get the table names and
field names from the database alright. But when I dynamically composed
the field names as elements of an array, such as the following:
my $var_declaration = "my @" . $tablename . " = (";
foreach $fieldname (@fieldnames)
{
$var_declaration .= "'" . $fieldname . "', ";
}
...... # some processing to get rid of the last comma and add the
enclosing ")"
and then I do the following:
eval $var_declaration;
print $var_declaration;
the print statement did print the array as follows:
my @USER = ('NAME', 'ADDRESS1', 'ADDRESS2', 'CITY', 'STATE',
'ZIPCODE');
I thought the eval will actually declare @USER array. But when I
actually tried to use @USER in the following code, Perl found no
elements at all. I did a size on @USER and I got a 1(one) in return.
Does that mean eval cannot be used to dynamically declare an array? Is
there another way to do it, or is it not doable at all?
Thanks for any help.
I'm trying to do the following: to retrive all table names from a
database and display them on a web application, and when a user selects
one table, display all its fields and the corresponding values on the
web. I'm doing it in Perl (ver 5.8.0). I can get the table names and
field names from the database alright. But when I dynamically composed
the field names as elements of an array, such as the following:
my $var_declaration = "my @" . $tablename . " = (";
foreach $fieldname (@fieldnames)
{
$var_declaration .= "'" . $fieldname . "', ";
}
...... # some processing to get rid of the last comma and add the
enclosing ")"
and then I do the following:
eval $var_declaration;
print $var_declaration;
the print statement did print the array as follows:
my @USER = ('NAME', 'ADDRESS1', 'ADDRESS2', 'CITY', 'STATE',
'ZIPCODE');
I thought the eval will actually declare @USER array. But when I
actually tried to use @USER in the following code, Perl found no
elements at all. I did a size on @USER and I got a 1(one) in return.
Does that mean eval cannot be used to dynamically declare an array? Is
there another way to do it, or is it not doable at all?
Thanks for any help.