Re: Time and again



On 2008-06-10 21:22, Jürgen Exner <jurgenex@xxxxxxxxxxx> wrote:
"Peter J. Holzer" <hjp-usenet2@xxxxxx> wrote:
On 2008-06-10 11:30, Jürgen Exner <jurgenex@xxxxxxxxxxx> wrote:
markdibley <markdibley@xxxxxxxxx> wrote:
I write that to a file and later I read it in

Why are you dumping the data into a file and then reading it back in?

That's what files are for. Why would you write something into a file if
you didn't plan to read it at some time?

Well, why would you write something to a file and then read it back into
the program if you already have the information in the program to begin
with?

Because you usually don't have it already in this process. Either
because it was written by a different process (that's the common case
for files - one process writes it, some other process reads it - maybe
only milliseconds later, maybe years later), or because your data
doesn't fit into memory all at once.

It all depends on what the OP meant with "later".

Is there some reason why you would think that the most stupid
possibility is the most likely?


I have seen code like

system ("myprog > temp.txt");
open (TMP, '<', 'temp.txt');
@result = <TMP>;

Here the programmer writes information to a file and later reads it back
into the program, but unless there are very special circumstances
probably nobody would call this good code.

However, the problem "how do I print a timestamp so that I can parse it
again" does not become easier if you replace the above code with

open(my $fh, '-|', 'myprog');
@result = <$fh>;
close($fh);

in both cases 'myprog' needs to write the timestamps in a defined
format, and your script needs to know how to parse that. Whether the
data between the two processes is exchanged via a temporary file or a
pipe (or a socket, or shared memory, or ...) is irrelevant to the
question.

A case where it was relevant would be something like this:

my $now = time();
print $fh localtime($now), "\n";
seek($fh, 0, 0);
$line = <$fh>;
$now = parse($line);

That's clearly stupid, but there is no reason to assume the OP would be
doing that, even if he wrote exactly that code into his demo script.
Because a demo script is there to illustrate the problem in the shortest
possible manner.


The OP already clarified that this is not what he was doing but that he
was dealing with log files. But that detail was missing in the original
post.

It was probably missing because the way he intended to use the file
(some process writes a file, some other process reads it) is the most
common case by far. Why should he mention that he wasn't going to do
something unlikely and stupid? Especially if that is completely
unrelated to the question?

hp

.



Relevant Pages

  • Re: Facebook anyone ?
    ... the fly fishing group started talkin' about old farts keeping ... at the behest of a friend of ours who has moved from Berkeley to ... so I am probably missing something. ... more stupid than coming here to argue about politics, music, Heiny Sex ...
    (rec.music.gdead)
  • Re: Credit card companies changing payment dates - A Trick?
    ... signature that they have received your tax return when you go there personally, so that if it goes missing, you'd have NO proof that you handed it in, and the court will obviously believe them before they ever believe you. ... Right brainbox, list here the dates I went to the tax office, since you're such a stupid know-it-all: ... Recorded delivery might occasionally go missing but given an early ...
    (uk.legal)
  • Re: Setting a mulifunction watch?
    ... John S. wrote: ... that surely there is some simple solution I'm missing. ... all stupid, and I have put a LOT of thought into this problem....and ... calendar. ...
    (alt.horology)
  • Question(s)? not answered etc.,etc.,etc
    ... The one QUESTION was where is the missing 2 per cent? ... have discovered I did indeed did not feel like answering a stupid ... stupid follow-up, idiot? ... an embarassment to RGL really, ...
    (rec.gambling.lottery)