use strict; use warnings; use CGI qw(:standard); use CGI::Search qw(:validators); my $TMPL_FILE = '/path/to/template'; my $DB_FILE = '/path/to/flat_file'; my $DB_SEPERATOR = '\|'; #### my @DB_FIELDS = ( [ 'num1', \&INTEGER, 1 ], [ 'text1', \&WORD, 0 ], [ 'email', \&EMAIL, 1 ], ); #### my %SEARCH = ( num1 => [ param("num1"), \&INTEGER ], email => [ param("email"), \&EMAIL ], ); #### my $RESULTS_PER_PAGE = param('RESULTS_PER_PAGE') || 0; # 0 means infinate my $MAX_RESULTS = 0; # Also infinate my $PAGE_NUMBER = param('PAGE') || 0; # Pagin numbering starts at 0 #### my $search = CGI::Search->new( script_name => $ENV{SCRIPT_NAME}, # Script location on web site--for paging template => $TMPL_FILE, # Path to HTML::Template file # Database options db_file => $DB_FILE, # Path to database file to search db_seperator => $DB_SEPERATOR, # Database field seperator db_fields => \@DB_FIELDS, # Referance to the database fields description # Paging options results_per_page => $RESULTS_PER_PAGE, max_results => $MAX_RESULTS, page_number => $PAGE_NUMBER, search_fields => \%SEARCH, # Referance to search fields ); #### my @data = $search->result(1) or die "Error: " . $search->errstr; my $tmpl = $search->result(1) or die "Error: " . $search->errstr; #### my %new_search = ( num1 => [ param("num1"), \&INTEGER ], email => [ param("other_email"), \&EMAIL ], ); my $new_tmpl = $search->result(1, \%new_search); ####

Search Results

No results were found for your search.

Error in database:

">Previous ">Next

##
## my $custom_validator = sub { if($_[0] =~ /\A(.*)/\z/) { return (1, $1, "Passed"); } else { return (0, undef, "$_[0] is not valid"); } }; #### my @DB_FIELDS = ( [ 'num1', $custom_validator, 1 ], [ 'email', \&EMAIL, 0 ], ... );