# # This software is Copyright 2005 by Elsevier Inc. You may use it # under the terms of the license at http://perl.plover.com/hop/LICENSE.txt . # ### ### query-composable ### ## Chapter 7 section 4 # usage: $dbh->query(fieldname, value) # returns all records for which (fieldname) matches (value) sub query { my $self = shift; my ($field, $value) = @_; my $fieldnum = $self->{FIELDNUM}{uc $field}; return unless defined $fieldnum; my $fh = $self->{FH}; seek $fh, 0, 0; <$fh>; # discard header line my $position = tell $fh; my $recno = 0; return sub { local $_; seek $fh, $position, 0; while (<$fh>) { $recno++; $position = tell $fh; my @fields = split $self->{FIELDSEP}; my $fieldval = $fields[$fieldnum]; return [$recno, @fields] if $fieldval eq $value; } return; }; } ## Chapter 7 section 4 # I LIKE PIE