#!/usr/bin/perl # # dbmusic.pl v0.0.17 - Database for music albums # Copyright (C) 2005, 2006, 2009 Stian Skjæveland # # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # use CGI qw(:standard); use strict; print header; print qq( Music database - Results ); &display_search(); print qq(

Music database - Results:


); my $param_search=lc(param('search')); my $param_alt=lc(param('alt')); my $file="/home/stunix/domains/atlantiscrew.net/public_html/stian/doc/list.txt"; # You may set this to whatever fits your system. my ($bandname, $albumtitle, $yearofrelease, $genre, $other, $i, $calc, $filelength, @filelines); my $found=0; my $count=0; open(DB_FILE, "<$file") || print "Cannot find file: $file

"; @filelines=; print "You're searching for \"$param_search\" in $param_alt (Back):

"; if ($param_alt) { &view_db(); } close(DB_FILE); sub view_db() { print qq( ); if ($param_alt eq "database") { for ($i=0; $i<999; $i++) { if (lc($filelines[$i])=~/$param_search/) { &view_db_results(); if (!($filelines[$i+1])) { last; } } } } for ($i=0; $i<999; $i++) { ($bandname, $albumtitle, $yearofrelease, $genre, $other)=split('@', $filelines[$i]); if ($param_alt eq "band name") { if (lc($bandname)=~/$param_search/) { &view_db_results(); } } if ($param_alt eq "album title") { if (lc($albumtitle)=~/$param_search/) { &view_db_results(); } } if ($param_alt eq "year of release") { if (lc($yearofrelease)=~/$param_search/) { &view_db_results(); } } if ($param_alt eq "genre") { if (lc($genre)=~/$param_search/) { &view_db_results(); } } if ($param_alt eq "other") { if (lc($other)=~/$param_search/) { &view_db_results(); } } if (!($filelines[$i+1])) { last; } } } print qq(

); if ($found ne 1) { print "

No match. Try different keyword(s)."; } else { $filelength=@filelines; print "

$count match(es) of total $filelength"; $calc=$count * 100 / $filelength; print " ($calc\%)."; } sub view_db_results() { ($bandname, $albumtitle, $yearofrelease, $genre, $other)=split('@', $filelines[$i]); print "$bandname$albumtitle$yearofrelease$genre$other
"; $count+=1; $found=1; } print qq(


Copyright (C) 2005, 2006, 2009 Stian Skjæveland.
Verbatim copying and redistribution of this entire page are permitted provided this notice is preserved.

Powered by Perl Valid HTML 4.01! ); sub display_search() { print qq(

Search for in
); }