Now that we have an array of valid fields to search through, it’s easy enough to add new ones. Go ahead and add “genre” to the list of valid fields:
@validFields = ("artist", "album", "song", "genre");
At the moment, the script doesn’t know about genre, so let’s tell the script about all of the fields the file has. Change the “split” lines to:
#split out the song information
($song, $duration, $artist, $album, $year, $rating, $ripdate, $track, $genre) = split("\t");
That’s it. Our script can now limit searches on genre as well as on artist, album, or song:
./show --artist linda --genre standard songs.txt
./show --genre video songs.txt
./show --genre spoken --song senator songs.txt