in reply to Re: Using Perl to Implement a simple Searchable Web Database
in thread Using Perl to Implement a simple Searchable Web Database

Sorry for the vagueness On the web server is a CSV Excel file, which is basically a spreadsheet that is readable as a text file. It seperates columns using a comma, and rows by going to the next line. The first element in each line is a unique part number. Information that follows it (seperated by commas) would be things like price, location, etc. The user on the website would type in a part number and the page would return the price, location, etc. information. This may seem like a very simple problem, but I have never used Perl in a practical application yet, so I'd like to use it here. Thanks, Doug
  • Comment on Re: Re: Using Perl to Implement a simple Searchable Web Database

Replies are listed 'Best First'.
Re: Using Perl to Implement a simple Searchable Web Database
by Abigail-II (Bishop) on May 28, 2002 at 17:45 UTC
    There are modules available to parse CSV files. But you might want to consider preprocessing the file into a DBM file, or a database, depending on the size of the file.

    Abigail

Re: Re: Re: Using Perl to Implement a simple Searchable Web Database
by cjf (Parson) on May 28, 2002 at 17:51 UTC

    This should get you started...

    #!/usr/bin/perl -wT use strict; use CGI; my $q = new CGI; my $number_to_find = $q->param("number"); open DATA, "data.txt" or die "Can't open file: $!"; while (<DATA>) { chomp; my @fields = split /,/; if ($fields[0] eq $number_to_find) { print_to_browser(@fields); } } close DATA; sub print_to_browser { my @data = @_; print $q->header("text/html"), $q->start_html("Error"), $q->h1("Relevant Data"), $q->p(@data), $q->end_html; }

    That's definately not the prettiest code, but it should give you an idea of what you need to do. You'll probably also want to read some of the CGI.pm docs and do a search or two on cpan for "CSV" to find some relevant modules.

      Thanks for your help, I just found out that the web server I am working on supports CGI and Perl (or so they say) I'll be testing it out to make sure. Thanks again! :-D