Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 1. GENERAL-PURPOSE UTILITIES > #4 Date Reminder - Pg. 10

GENERAL-PURPOSE UTILITIES 10 This gives two hashes, the one referenced by $file_info containing the old information and %real_info reflecting the current state of the system. Now all you have to do is compute the difference between the two. First you go through the %real_info hash and see if any files have been added or changed: 58 foreach my $file (sort keys %real_info) { 59 if (not defined($file_info->{$file})) { 60 print "New file: $file\n"; 61 } else { 62 if ($real_info{$file} ne $file_info->{$file}) { 63 print "Changed: $file\n"; 64 } 65 # else the same 66 delete $file_info->{$file}; 67 } 68 } This loop also has the side effect of deleting all the entries of $file_info that have a correspond- ing entry in %real_info. This means that when the loop finishes, the only files that are left in $file_info are the files that were deleted since the last time the program was run. You print them out to tell the user what disappeared: 75 foreach my $file (sort keys %$file_info) { 76 print "Deleted: $file\n"; 77 } 78 The final step is to write out the information on the existing files so that it can be used in a later run. Again, the Storable module is used; this time the nstore function is called to store the %real_info hash. (The nstore function stores the data in a portable format; the store function's