http://www.perlmonks.org?node_id=1017090


in reply to why does open ">..." sometimes touches the directory?

G'day Mark,

The directory is a file. You can view it in an editor. When you open a file for writing, even if you don't write anything, the information in the directory file will change and, accordingly, so will the timestamp. You can see this for yourself at the command line (i.e. without using perl) - here's a sample run:

ken@ganymede: ~/tmp $ ls -al check_dir_touch ls: check_dir_touch: No such file or directory ken@ganymede: ~/tmp $ mkdir check_dir_touch ken@ganymede: ~/tmp $ ls -al check_dir_touch total 0 drwxr-xr-x 2 ken staff 68 5 Feb 20:12 . drwxr-xr-x 211 ken staff 7174 5 Feb 20:12 .. ken@ganymede: ~/tmp $ view check_dir_touch --------------------- Editor window shows various info with no files listed (exit editor without attempting to save anything) --------------------- ken@ganymede: ~/tmp $ > check_dir_touch/fred ken@ganymede: ~/tmp $ ls -al check_dir_touch total 0 drwxr-xr-x 3 ken staff 102 5 Feb 20:19 . drwxr-xr-x 210 ken staff 7140 5 Feb 20:18 .. -rw-r--r-- 1 ken staff 0 5 Feb 20:19 fred ken@ganymede: ~/tmp $ view check_dir_touch --------------------- Editor window now shows "fred" (exit editor without attempting to save anything) ---------------------

I agree with vinoth.ree's comment about using the 3-argument form of open; however, that won't change the behaviour of the underlying operating system.

-- Ken