Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: check for latest file, remove and touch file?

by AnomalousMonk (Archbishop)
on Jan 05, 2016 at 19:19 UTC ( [id://1152008]=note: print w/replies, xml ) Need Help??


in reply to Re: check for latest file, remove and touch file?
in thread check for latest file, remove and touch file?

open my $fh, '>', $f or die "Can't write to $f: $!\n";

Won't open-ing the file named  $f in  '>' write mode clobber the current contents of the file at the same time it changes time/date? Wouldn't  '>>' append mode be better?


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^3: check for latest file, remove and touch file?
by mr_mischief (Monsignor) on Jan 05, 2016 at 20:39 UTC

    Assuming the file already exists, yes append mode would be better. If it doesn't already exist, then the two are equivalent. To make it more similar to touch it should be appending. You're right about that.

Re^3: check for latest file, remove and touch file?
by GotToBTru (Prior) on Jan 07, 2016 at 15:48 UTC

    At least in my environment (AIX), opening the file in append mode without adding any content does not update the modification date of the file.

    $: date Thu Jan 7 09:37:01 CST 2016 $: touch step.file $: ls -l step.file -rw-r--r-- 1 wlsedi wlsedi 0 Jan 07 09:37 step.file $: date Thu Jan 7 09:38:01 CST 2016 $: touch step.file $: ls -l step.file -rw-r--r-- 1 wlsedi wlsedi 0 Jan 07 09:38 step.file $: date Thu Jan 7 09:39:38 CST 2016 $: perl -de 1 Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 1 DB<1> open $fh,'>>','step.file' DB<2> close $fh DB<3> q $: ls -l step.file -rw-r--r-- 1 wlsedi wlsedi 0 Jan 07 09:38 step.file

    Opening in write does have the un-touchlike side effect of wiping out any content. In this particular instance, that is of no consequence, but using the code as a generic replacement for touch is problematic.

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1152008]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found