Perl logo

Perl Refreshments ⌘

Hashes #5 - Delete a record

While I'd love to maintain my music collection forever, stuff happens and we may no longer have a particular CD. Now we have to delete it from our library.

print "Deleting 'Aural Float - Freefloat' ...\n";

delete $music{'Aural Float'}{'Freefloat'}; # THAT'S IT!

($Andx,$Cndx) = (1,1); # reset counters

foreach $artist (sort keys (%music)) {
    print "$Andx $artist\n";
    $Andx++;
    $Cndx=1; # initialize for each artist
    foreach $cd (sort keys $music{$artist}) {
        print "\t $Cndx $cd\n";
        $Cndx++;
        foreach $tracknum (sort keys $music{$artist}{$cd}) {
            print "\t\t$tracknum $music{$artist}{$cd}{$tracknum}\n";
       }
    }
}

Remember to reset any counters you may be using ($Andx and $Cndx) after deletions.

A good exercise may be to add fields like 'Genre' and 'Track Length'.


-30-