perlでmysqlからselectする(コマンドライン編)

#!/usr/bin/perl

use strict;
use DBI;

# MySQL
our $DB_NAME = "perldb";
our $DB_USER = "hoge";
our $DB_PASS = "hogehoge";
our $DB_HOST = "localhost";
our $DB_PORT = "3306";

my $dbh = DBI->connect("dbi:mysql:dbname=$DB_NAME;host=$DB_HOST;port=$DB_PORT","$DB_USER","$DB_PASS") or die "$!\n Error: failed to connect to DB.\n";
my $sth = $dbh->prepare("SELECT * FROM t1;");
$sth->execute();
while (my $ary_ref = $sth->fetchrow_arrayref) {
  my ($a, $b) = @$ary_ref;
  print "$a, $b\n";
}
$sth->finish;
$dbh->disconnect;

おおおおおおお、selectできるやんけ。
[vagrant@localhost cgi-bin]$ perl hoge.pl
1, asakura
2, adachi
3, kobayakawa
1, 1st

ということは、cgiも行けるかな(ワクワク)^^