perl 把内存当数据库的方法

perl 把内存当数据库的方法

#!/usr/bin/perl
use DBI;
my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):');
$dbh->do("CREATE TABLE test (id TEXT,phrase TEXT)");
$dbh->do("INSERT INTO test VALUES (1,'foo')");
$dbh->do("INSERT INTO test VALUES (2,'bar')");
$dbh->do("UPDATE test SET phrase='baz' WHERE id = '2'");
$dbh->do("DELETE FROM test WHERE id = '1'");
my $classes_sth = $dbh->prepare( "SELECT id,phrase FROM test" );
$classes_sth->execute;
while (my($id,$class_title) = $classes_sth->fetchrow_array) {
print "$id,$class_title \n";
}