Re: overwrite?

2017-09-25 Thread ToddAndMargo

On 09/25/2017 09:42 AM, Parrot Raiser wrote:

Have you considered simply "touch"ing the file? That updates the timestamp.



yes.

The way I actually did it forced me to (keep) learn(ing)
how to write and read to files.

A lot of the things I do, I do the hard way so that I am
forced to learn.

I can not do s/ and m/ and if ( $x ~~~/xxx/ ) without having
to look at a reference.  Yippee!  I think.  maybe.



Re: overwrite?

2017-09-25 Thread Parrot Raiser
Have you considered simply "touch"ing the file? That updates the timestamp.


Re: overwrite?

2017-09-24 Thread ToddAndMargo

On 09/24/2017 11:23 PM, ToddAndMargo wrote:

write you t

 ^^ out


Re: overwrite?

2017-09-24 Thread ToddAndMargo

On 09/24/2017 10:57 PM, Brandon Allbery wrote:
On Mon, Sep 25, 2017 at 1:41 AM, ToddAndMargo > wrote:


I suppose I should say at this point that the purpose of the file
is to be a single line with the date the program was last run
in it.  If the current date's month and the month in the file
differ, it triggers an event in my program.


Had you considered using the file last-modified timestamp instead?


That is an idea.

I currently write you the whole date time and offset


Re: overwrite?

2017-09-24 Thread Brandon Allbery
On Mon, Sep 25, 2017 at 1:41 AM, ToddAndMargo  wrote:

> I suppose I should say at this point that the purpose of the file
> is to be a single line with the date the program was last run
> in it.  If the current date's month and the month in the file
> differ, it triggers an event in my program.


Had you considered using the file last-modified timestamp instead?

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: overwrite?

2017-09-24 Thread ToddAndMargo

On 09/24/2017 10:23 PM, ToddAndMargo wrote:

On 09/23/2017 12:34 PM, Brandon Allbery wrote:
On Sat, Sep 23, 2017 at 2:34 AM, ToddAndMargo <mailto:toddandma...@zoho.com>> wrote:


I see ":truncate".  This seems liek it will do the trick.
Problem: I would like to read from the file first before
truncating (ro).

Is there a way to do this, or should I
1) open the handle with :ro
2) read what I want from it
3) close the handle
4) reopen the handle with :w and overwrite what I want?


You have to do it the long way. I don't think we expose a binding to 
ftruncate() that would let you open it r/.w, red from it, truncate, 
and write.


That said, there's actually a good reason for that: is it okay to 
trash the file if something goes wrong? You might prefer to *rename* 
the old file instead of overwriting, so you can recover if necessary.


That is what I did.  Thank you for the confirmation!


I suppose I should say at this point that the purpose of the file
is to be a single line with the date the program was last run
in it.  If the current date's month and the month in the file
differ, it triggers an event in my program.

--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: overwrite?

2017-09-24 Thread ToddAndMargo

On 09/23/2017 12:34 PM, Brandon Allbery wrote:
On Sat, Sep 23, 2017 at 2:34 AM, ToddAndMargo <mailto:toddandma...@zoho.com>> wrote:


I see ":truncate".  This seems liek it will do the trick.
Problem: I would like to read from the file first before
truncating (ro).

Is there a way to do this, or should I
1) open the handle with :ro
2) read what I want from it
3) close the handle
4) reopen the handle with :w and overwrite what I want?


You have to do it the long way. I don't think we expose a binding to 
ftruncate() that would let you open it r/.w, red from it, truncate, and 
write.


That said, there's actually a good reason for that: is it okay to trash 
the file if something goes wrong? You might prefer to *rename* the old 
file instead of overwriting, so you can recover if necessary.


That is what I did.  Thank you for the confirmation!


Re: overwrite?

2017-09-23 Thread Brandon Allbery
On Sat, Sep 23, 2017 at 2:34 AM, ToddAndMargo  wrote:

> I see ":truncate".  This seems liek it will do the trick.
> Problem: I would like to read from the file first before
> truncating (ro).
>
> Is there a way to do this, or should I
>1) open the handle with :ro
>2) read what I want from it
>3) close the handle
>4) reopen the handle with :w and overwrite what I want?
>

You have to do it the long way. I don't think we expose a binding to
ftruncate() that would let you open it r/.w, red from it, truncate, and
write.

That said, there's actually a good reason for that: is it okay to trash the
file if something goes wrong? You might prefer to *rename* the old file
instead of overwriting, so you can recover if necessary.

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


overwrite?

2017-09-22 Thread ToddAndMargo

Hi All,

I want to overwrite a file.

Looking at:
https://docs.perl6.org/routine/open

I see ":truncate".  This seems liek it will do the trick.
Problem: I would like to read from the file first before
truncating (ro).

Is there a way to do this, or should I
   1) open the handle with :ro
   2) read what I want from it
   3) close the handle
   4) reopen the handle with :w and overwrite what I want?

Many thanks,
-T