in reply to existing file is modified or not

I want to know is this the right way to find whether the existing file is modified or not ?

IMHO there is no 'right way' or 'wrong way'. It all depends on the goal you wish to achive. If this works for you, go ahead.

One thing you should be aware of, is the race condition you are introducing: what is someone edits the file after you read it, and before you stumble over it? You should introduce some kind of locking mechanism to be sure you get it right!

Cheers,
Paul

Replies are listed 'Best First'.
Re^2: existing file is modified or not
by steves (Curate) on Nov 25, 2004 at 13:25 UTC

    Another approach would be to create your new file as a unique temporary file, then use something like Text::Diff to diff the two files. If they differ, you remove the old one and rename the new (temporary) one to the name of the old removed file. If they are the same, you just remove the temporary file.

    I agree about the locking: to do this without race conditions, you should consider locking the target file. You may also be able to use file modification times to see if the file has changed since you started looking at it.