Jim Gibson <jimsgib...@gmail.com> writes: > On Jun 12, 2013, at 2:33 AM, lee wrote: > >> Jim Gibson <jimsgib...@gmail.com> writes: >> >>> >>> The first thing to do would be to check the file size. If the file >>> size has changed, then the file has been modified. So you will want to >>> save the file size. >> >> The file might be modified without changing its size ... > > That is true. The advantage of checking the file size first is that it is a > very quick test that does not require reading the entire file. You can get > the file size in Perl one of two ways: > > 1. my $size = (stat($filename))[7]; > > or > > 2. my $size = -s $filename;
Number 2 is particularly nice :) A combination of size and mtime might be useful. I'd have to handle an exception for instances when either the size or the mtime has changed but not both. That's something to think about; it's surely much more efficient than computing hashs ... #!/bin/perl use strict; use warnings; chomp $ARGV[0]; my @info = (stat ($ARGV[0] ) ); printf("%s: %d bytes, %d mtime\n", $ARGV[0], $info[7], $info[9] ); Some more questions to this: + Is "chomp $ARGV[0];" even allowed? I wouldn't do anything like that in C :) + Is "print" and "printf" pretty much the same thing implementation wise? I'm wondering if "printf" might involve more overhead so it might be less efficient, depending on what you're doing. + When I create files with lines like "filename:size:mtime" or "filename:hash", is there something built in to read a syntax like this into, let's say, an array like "my @fileinfo;" with $fileinfo[0] being the file name, $fileinfo[1] the hash? Such 'key:value:...' combinations is probably something frequently used. I'm finding some examples to this and don't know what would be the best way to do it. -- "Object-oriented programming languages aren't completely convinced that you should be allowed to do anything with functions." http://www.joelonsoftware.com/items/2006/08/01.html -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/