in reply to Re^2: XML compression?
in thread XML compression?

It is as easy as:
use strict; use Digest::file qw(digest_file_hex); die 'XML file has been changed!\n' unless digest_file_hex( 'test.xml', "MD5" ) eq 'e253b427caacb6f0781f337a90658c6a'; print "Continue\n";

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^4: XML compression?
by Anonymous Monk on Nov 11, 2008 at 20:36 UTC
    Perfect...thank you!

    I found another example that offers a few more stats if anyone else is interested

    use Getopt::Std; use Digest::MD5 qw(md5); my @statnames = qw(dev ino mode nlink uid gid rdev size mtime ctime blksize blocks md5); getopt('p:c:'); die "Usage: $0 [-p <filename>|-c <filename>]\n" unless ($opt_p or $opt_c); if ($opt_p){ die "Unable to stat file $opt_p:$!\n" unless (-e $opt_p); open(F,$opt_p) or die "Unable to open $opt_p:$!\n"; $digest = Digest::MD5->new->addfile(F)->hexdigest; close(F); print $opt_p,"|",join('|',(lstat($opt_p))[0..7,9..12]),"|$digest", +"\n"; exit; } if ($opt_c){ open(CFILE,$opt_c) or die "Unable to open check file $opt_c:$!\n"; while (<CFILE>){ chomp; @savedstats = split('\|'); die "Wrong number of fields in \'$savedstats[0]\' line.\n" unless ($#savedstats == 13); @currentstats = (lstat($savedstats[0]))[0..7,9..12]; open(F,$savedstats[0]) or die "Unable to open $opt_c:$!\n"; push(@currentstats,Digest::MD5->new->addfile(F)->hexdigest); close(F); &printchanged(\@savedstats,\ @currentstats) if ("@savedstats[1..13]" ne "@currentstats"); } close(CFILE); } sub printchanged { my($saved,$current)= @_; print shift @{$saved},":\n"; for (my $i=0; $i <= $#{$saved};$i++){ if ($saved->[$i] ne $current->[$i]){ print " ".$statnames[$i]." is now ".$current->[$i]; print " (".$saved->[$i].")\n"; } } }