sub bynumber { $a <=> $b; } srand; open(Artist,"){ ($artno,$artist,$abcartist) = split(/\|/); chop $abcartist; $artist{$artno} = $artist; $abcartist{$artno} = $abcartist; $maxartno = $artno if ($artno > $maxartno); $i++; } print "Artist: $i records\n"; $i=0; while(){ ($one,$two) = split(/\|/); chop $two; @temp = split(/\|/,$seealso{$one}); $seealso{$one} = join('|',@temp,$two); @temp = split(/\|/,$seealso{$two}); $seealso{$two} = join('|',@temp,$one); $i++; } print "SeeAlso: $i records\n"; $i = 0; while(){ ($albno,$artno,$album,@details) = split(/\|/); $artno{$albno} = $artno; $album{$albno} = $album; $i++; } print "Album: $i records\n"; $i = 0; $maxsongno = 0; while(){ ($songno,$song)=split(/\|/); chop $song; $song{$songno} = $song; # $song =~ s/&/and/; # $song =~ tr/A-Z/a-z/; # $song =~ tr/a-z0-9 //cd; # @temp = split(/\|/,$songno{$song}); # push(@temp, $songno); # $songno{$song} = join('|',@temp); $maxsongno = $songno if ($songno > $maxsongno); $i++; } print "Song: $i records\n"; $i=0; while(){ ($onalb,$onsong,$odetails) = split(/\|/); chop $odetails; @temp = split(/\|/,$onalb{$onsong}); $onalb{$onsong} = join('|',@temp,$onalb); $odetails{"$onalb|$onsong"} = $odetails; $i++; } print "On: $i records\n"; $i = 0; while(){ ($sartno,$ssongno) = split (/\|/); chop $ssongno; @temp = split(/\|/,$sartno{$ssongno}); $sartno{$ssongno} = join('|',@temp,$sartno); $i++; } print "Sings: $i records\n"; close Artist; close Album; close Song; close On; close Sings; close SeeAlso; print "aLbum aRTist Song Quit\n"; while(1){ # do this forever print "Enter navigation code, or H for help:"; $input = ; chop $input; $call = substr($input, 0, 1); CHOICE: { if ("L" eq $call || "l" eq $call){ &album(substr($input,1)); last CHOICE; } if ("R" eq $call || "r" eq $call){ &artist(substr($input,1), 'r'); last CHOICE; } if ("T" eq $call || "t" eq $call){ &artist(substr($input,1), 't'); last CHOICE; } if ("S" eq $call || "s" eq $call){ &song(substr($input,1)); last CHOICE; } if ('*' eq $call){ &pick(substr($input,1,1)); last CHOICE; } if ("H" eq $call || "h" eq $call){ &help; last CHOICE; } if ("Q" eq $call || "q" eq $call){ exit 0; } print "Type H for help.\n" } #CHOICE } sub artist{ local($argument, $searchtype) = @_; if ($argument !~ /^\d*$/) { # not a number $temp = -1; foreach $artno (sort bynumber (keys %artist)) { if (($artist{$artno} =~ /^$argument/i) || ($abcartist{$artno} =~ /^$argument/i)) { print "\u$searchtype$artno:$artist{$artno}\n"; $temp = (-1 == $temp) ? $artno : -2; } } return 0 if ($temp < 0); print "Right?"; return 0 if ( !~ /^y/i); $artno = $temp; } else { $artno = $argument; } if (! defined($artist{$artno})){ # no such artist print "Invalid artist.\n"; return 1; #like anyone cares } print "\u$searchtype$artno:$artist{$artno} ($abcartist{$artno})\n"; if ('r' eq $searchtype) { foreach $albno (sort bynumber (keys %album)) { if ($artno{$albno} == $artno) { print "\tL$albno:$album{$albno}\n"; } } } elsif ('t' eq $searchtype) { foreach $songno (sort bynumber (keys %sartno)) { if ($sartno{$songno} =~ /^(\d*\|)*$artno(\|\d*)*$/) { print "\tS$songno:$song{$songno}\n"; } } } if (defined($seealso{$artno})) { print "See Also:\n"; foreach $seealso (sort bynumber (split(/\|/,$seealso{$artno}))) { print "\t\u$searchtype$seealso:$artist{$seealso}\n"; } } } sub album{ local($argument) = @_; if ($argument !~ /^\d*$/) { # not a number $temp = -1; foreach $albno (sort bynumber (keys %album)) { if ($album{$albno} =~ /^$argument/i) { print "L$albno:$album{$albno} by $artist{$artno{$albno}}\n"; $temp = (-1 == $temp) ? $albno : -2; } } return 0 if ($temp < 0); print "Right?"; return 0 if ( !~ /^y/i); $albno = $temp; } else { $albno = $argument; } if (! defined($album{$albno})){ # no such album print "Invalid album.\n"; return 1; #like anyone cares } print "L$albno:$album{$albno}\n"; print "\t\tby R$artno{$albno}:$artist{$artno{$albno}}\n"; foreach $onrec (sort bynumber (keys %odetails)) { if ($onrec =~ /^$albno\|/) { ($nothing, $songno) = split (/\|/, $onrec); print "\tS$songno:$song{$songno}\n"; } } } sub song{ local($argument) = @_; if ($argument !~ /^\d*$/) { # not a number $temp = -1; foreach $songno (sort bynumber (keys %song)) { if ($song{$songno} =~ /^$argument/i) { print "S$songno:$song{$songno}\n"; $temp = (-1 == $temp) ? $songno : -2; } } return 0 if ($temp < 0); print "Right?"; return 0 if ( !~ /^y/i); $songno = $temp; } else { $songno = $argument; } if (! defined($song{$songno})){ # no such album print "Invalid song.\n"; return 1; #like anyone cares } print "S$songno:$song{$songno}\n"; @sartno = split (/\|/, $sartno{$songno}); $temp = shift @sartno; print " by\tR$temp:$artist{$temp} \n"; while ($sartno = shift @sartno){ print " and\tR$sartno:$artist{$sartno}\n"; } @onalb = split (/\|/, $onalb{$songno}); $temp = shift @onalb; print " on\tL$temp:$album{$temp}\n"; while ($onalb = shift @onalb){ print " and\tL$onalb:$album{$onalb}\n"; } } sub pick { local($picktype) = @_; if (("\u$picktype" eq 'R')||("\u$picktype" eq 'T')){ @temp = keys %artist; $arg = $temp[int(rand(scalar(@temp)))]; &artist($arg, $picktype); } elsif ("\u$picktype" eq 'L'){ @temp = keys %album; $arg = $temp[int(rand(scalar(@temp)))]; &album($arg); } elsif ("\u$picktype" eq 'S'){ @temp = keys %song; $arg = $temp[int(rand(scalar(@temp)))]; &song($arg); } } sub help { print <<'EndOfHelp'; This is a database of the artists, albums, and songs in Denis's vinyl collection. You can query any of those three lists. The first character of your input specifies which list is queried and what info is returned by a successful lookup: R: Artists: List of albums T: Artists: List of songs L: Albums: Artist, list of songs S: Songs: Artist(s), Album(s) If the remainder is a number, that [album,artist,song] number is looked up. Otherwise, the remainder is checked, non-case-sensitively, against everything in the list. It assumes your input is the beginning of the name, but you can get around that if you're clever and know Perl regular expression syntax. (It uses the call /^$arguments/i if that helps you any.) First names and last names will both work fine for solo or pseudosolo artists. Also, you can get a random artist, album, or song by entering something like "*S", where the s can be any of the four lookup codes. This has been crashing my 486 lately, so you may want to save things before running it on a personal computer. I doubt it will break a box running a real operating system. But, Caveat Ludator. EndOfHelp }