A Continental Perl Adventure Day One 13 of 96 : [PREV] [NEXT]

Example of a closure

A standard use of DBI.

my $sth = $dbh->prepare($sql);
$sth->execute(@args)
while ( my $record = $sth->fetchrow_arrayref() ) {
  # do something with $record
}

$sth->fetchrow_arrayref() is the iterator. It returns one record at a time from the result set of the query.

Or if you haven't used DBI, what about filehandles?

open FH "myfile.txt" or die "myfile.txt: $!\n";
while(<FH>) {
  # do something
}
close FH;

© 2003 Barbie barbie@missbarbell.co.uk Home http://birmingham.pm.org/