请教指针地址的问题

请教指针地址的问题

请教指针地址的问题
~~最近由于班里组织研究小组,我找来找去不见Perl,只好加入了个VB.net的,
花去不少时间,极大影响我研究FastCGI的步骤~~~不过最近看了一些程序设计
语言原理的书,发现haskell竟然是LISP的一个分支。拉远了,呵,还是问问题吧。

就是如下一段代码:
#!c:/perl/bin/perl.exe

use DBI;

my $dbh = DBI->connect("dbi:ODBC:driver=Microsoft Access Driver (*.mdb);dbq=sakurasky.mdb") || die ("DBI Connect Failed $!");

my $sql_cmd1 = "SELECT * FROM boardstyle";

my $sth = $dbh->prepare($sql_cmd1);
$sth->execute();

my $dat;
my %loop_hash;
my @loop_array;
while ($dat=$sth->fetchrow_hashref) {
$loop_hash{BASENAME} = $dat->{basename};
$loop_hash{BOARDNAME} = $dat->{boardname};
$loop_hash{BOARDTYPE} = $dat->{boardtype};
$loop_hash{BOARDINFO} = $dat->{boardinfo};
$loop_hash{BOARDADMIN} = $dat->{boardadmin};

push(@loop_array,\%loop_hash);
}

my $var = \@loop_array;

$sth->finish;
$dbh->disconnect;

exit;

每次循环存储到@loop_array数组的都是同一个地址值(比如说HASH(0x17b2d5c) ),
由于后一条记录和前一条记录键的名称是相同的,后一条记录就会把前一条记录覆盖了。
最后得出的结果@$var虽然是有N个HASH(0x17b2d5c),但全是最后一条记录,如果我
想构建出象下面这种数组散列应该怎样做呢?

my @loop_array = (
{ 'BASENAME' => 'data1','BOARDNAME' => 'data2' ,'BOARDTYPE' => 'data3' },
{ 'BASENAME' => 'data01','BOARDNAME' => 'data02' ,'BOARDTYPE' => 'data03' },
{ 'BASENAME' => 'data001','BOARDNAME' => 'data002' ,'BOARDTYPE' => 'data003' }
);

#注析:data1代表第一次从数据库取出的数值,data01代表第二次取出的数值,依此类推...




   

while ($dat=$sth->fet.
while ($dat=$sth->fetchrow_hashref) {
push(@loop_array, {
'BASENAME' => $dat->{basename},
'BOARDNAME' => $dat->{boardname},
'BOARDTYPE' => ..
} );
}
#!c:/perl/bin/perl.exe #!c:/perl/bin/perl.exe

use DBI;

my $dbh = DBI->connect("dbi:ODBC:driver=Microsoft Access Driver (*.mdb);dbq=sakurasky.mdb") || die ("DBI Connect Failed $!");

my $sql_cmd1 = "SELECT * FROM boardstyle";

my $sth = $dbh->prepare($sql_cmd1);
$sth->execute();

my $dat;

my @loop_array;
while ($dat=$sth->fetchrow_hashref) {
my %loop_hash;
$loop_hash{BASENAME} = $dat->{basename};
$loop_hash{BOARDNAME} = $dat->{boardname};
$loop_hash{BOARDTYPE} = $dat->{boardtype};
$loop_hash{BOARDINFO} = $dat->{boardinfo};
$loop_hash{BOARDADMIN} = $dat->{boardadmin};

push(@loop_array,\%loop_hash);
}

my $var = \@loop_array;

$sth->finish;
$dbh->disconnect;

exit;
[color=red][/color][color=#DC143C][/color][color=#DC143C][/color][b][/b]
why not fetch all hashref
$hash_ref = $dbh->selectall_hashref($statement, $key_field);
不是更好一点么?为啥要自己动手去做呢?
具体信息 perldoc DBI
谢谢
已经解决了,果然证明了Perl中条条大路通罗马的名言,三种方法都可以,
其中poseidon的是HTML::Template里的标准写法,呵,感谢各位.[CCB]1[/CCB]