reading from / writing to file : 2 dumb questions

Richmond richmondmathewson at gmail.com
Tue Sep 9 11:46:15 EDT 2014


On 09/09/14 18:39, jbv at souslelogo.com wrote:
> Hi list
>
> I am trying to improve the speed of a large script including
> many loops.
> Could anyone explain why :
>
> - question 1 : if a text file contains "toto", after running the
> following lines
>     open file tpath
>     read from file tpath until EOF
>     write (it & return & "titi") to file tpath
>     close file tpath
>
> the file contains :
>    totototo
>    titi
Because you are doing this:

reading the contents of file tpath

and THEN writing that ('toto') and 'titi' back to the file.

So 'toto' + 'toto' + return + 'titi' is what you end up with.
---------------------------------------------------------------
>
> and when running these lines
>     open file tpath
>     read from file tpath until EOF
>     close file tpath
>     open file tpath
>     write (it & return & "titi") to file tpath
>     close file tpath
>
> the file contains :
>     toto
>     titi

Because here you close the file for reading and then open it again.

In the first case your information is appended to the existing file.

In the second case your information overwrites the existing file.
-----------------------------------------------------------------
> - question 2
>
> why is this line
>    put "toto" after URL ("binfile:/hd/myFile.txt")
>
> much slower than
>           open file tpath
>           read from file tpath until EOF
>           close file tpath
>           open file tpath
>           write (it & return & "toto") to file tpath
>           close file tpath
I don't know.
> Thanks in advance.
> jbv
>
>
>
Best, Richmond.




More information about the use-livecode mailing list