tie %artist, DB_File, "$vardir/artists.db"; tie %album, DB_File, "$vardir/title.db"; tie %track, DB_File, "$vardir/track.db"; #### # tie to new files to keep from accidentally # re-using old values and to not update the db # while it may be being read by the search client my $vardir = "/var/music"; # whatever tie %artist, DB_File, "$vardir/.#artist.db#"; tie %album, DB_File, "$vardir/.#album.db#"; tie %track, DB_File, "$vardir/.#track.db#"; tie %by_id, DB_File, "$vardir/.#by_id.db#"; tie %keyword, DB_File, "$vardie/.#keyword.db#"; my $id = 0; open INDEX, "$vardir/my_ascii_index.csv" or die "can't index if I can't read the index: $!"; for my $line () { my $this_artist, $this_album, @album_tracks = split /,/, $line; $artist{$this_artist} .= $id . ','; $album{$this_album} .= $id . ','; for my $this_track (@album_tracks) { $track{$this_track} .= $id . ','; } $by_id{$id} = join "\x00", $this_artist, $this_album, @album_tracks; for my $word (split /\s/, join (" ", $this_artist, $this_album, @album_tracks) ) { $keyword{$word} .= $id . ','; } $id++; } close INDEX; untie %album; untie %artist; untie %by_id; untie %album; untie %keyword; #[the data file assumed above would read like: # Pearl Jam,ten,Jeremy,Black,... # and could be created in Gnumeric or Excel as a CSV file] #### # use CGI and get your query words in whatever form # load them into e.g. $artist_query, $title_query, &c. my @result_ids = (); if ($artist{$artist_query}) { push @result_ids, $artist{$artist_query} } if ($track{$track_query}) { push @result_ids, $track{$track_query} } if ($album{$album_query}) { push @result_ids, $album{$album_query}; } for my $word (split /\s/, $keyword_query) { if ($keyword{$word}) { push @result_ids, $keyword{$word}; } } unless (@result_ids) { print "

No results

"; return; } print "

Found " . (scalar @result_ids) . ":

    "; for my $id (@result_ids) { my $artist, $album, @tracks = split /\x00/, $by_id{$id}; print "
  1. $album by $artist
      "; for my $track (@tracks) { print "
    1. $track
    2. \n"; } print "
  2. \n\n"; } print "\n
\n"; return;