The FreeDB searches are done with the search criteria given
earlier, either interactively or through command-line switches.
Again, I use the
%freedb_searches hash to make a list of searches.
For each search, I specify the search words given by the user and
add the words given to the
-all switch. Note that each "word" can
contain spaces; the words are single search units as far as
autotag.pl and FreeDB are concerned.
Once results are returned from the FreeDB database, they are put in
%found_disks hash. This hash is created for every keyword, so old
results don't show up. When the
-or switch is specified by the user,
I simply add the results to the other results. Otherwise, the
@common array is used to see what results are in common with previous results (the AND
mode is implicit, meaning that by default search results must match
all keywords requested). The
List::Compare module is
used to make an intersection of two lists. Doing it manually is
possible and not too hard, but why spend the time and effort when a
tested and probably much faster implementation already exists?
Note again that all search results are just string IDs that correspond to an album in the FreeDB database. Thus, I can use them as hash keys, lists of strings to be searched, etc.
Finally, I add the filtered results to the
%discs hash, and increment
%disc_counts entry for each found album. The disk counts will be
used later. Incidentally, I use "disc" instead of "disk" in variable
names because that's what FreeDB uses.
When the results are all in place, I delete the ones that are not in
@common. Recall that with
@common array contains all the
The loop through the keys of
%discs is simple, using
grep() to see if
a disc is in
@common. I could have used a hash to optimize this loop
further, but frankly I don't think it would have made a difference at
all unless the user was finding hundreds of thousands of albums.
If no albums were left in
%discs, I'm done and make a graceful exit
with a message.