Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest Chrome or Safari browser. Firefox 10 (to be released soon) will also handle it.

DBプログラミングにおけるイテレータと配列の話

O/R Mapper の select のインターフェース

イテレータの場合

my $itr = $teng->search('user', +{name => 'nekokak'}, +{order_by => 'id'});
while ( my $row = $itr->next() ) {
    # $row を使ってアレコレする
}

配列の場合

my @rows = $teng->search('user', +{name => 'nekokak'}, +{order_by => 'id'});
# Row object の配列が返る

それぞれの特徴

使い分け

使い分け(2)

while ( my $row = $itr->next() ) {
    do_something_with_row($row);
    $row->nanika_suru();
}
my @rows = $teng->search('user', +{name => 'nekokak'}, +{order_by => 'id'});
$self->important_shori(@rows);

イテレータを使う場合の注意

my @array = ();
my $itr = $teng->search('user', +{name => 'nekokak'}, +{order_by => 'id'});
while ( my $row = $itr->next() ) {
    # $row を使ってアレコレする
    push @array, $some_data; # これだと行数分 @array が作られるので意味がない
}

おしまい

Use a spacebar or arrow keys to navigate