I have alerted the OP, in a private message, that I have answered their question over here.I have a file with 50,000 rows of about 25 chars per row. I only need to read roughly the most recent 200 rows until something is true and it saves time not to load the entire file using put ULR "file:filename" into tWhatever
I can append data to the file easily (a line at a time) but then I'd have to read the file backwards - which I can't see how to do.
OR
I can prepend data to the file then read in the normal order, but I can seem to do that without it destroys the previous data.
It's odd I can't find a solution as I'm sure this is a problem that has been faced by so many people so many times, that there is an elegant solution that I am missing. In short, I DO NOT want to load the entire file into memory using the URL command. I just want to read the 200 most recently contributed lines for the purpose of time efficiency - in this case, speed matters.
Answering Questions from elsewhere #1: Reading and writing text to / from a file
Forum rules
Be kind.
Be kind.
- richmond62
- Posts: 4833
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Answering Questions from elsewhere #1: Reading and writing text to / from a file
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4833
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Answering Questions from elsewhere #1: Reading and writing text to / from a file
This is extremely easy . . .
I knocked together a very simple stack:
- -
The button "GET'EM" contains this code:
Obviously the URL is 'peculiar' to my machine and the document I am using for this test.
I knocked together a very simple stack:
- -
The button "GET'EM" contains this code:
Code: Select all
on mouseUp
put empty into fld "fINPUT"
put 1 into LYNE
repeat until LYNE > 200
put line LYNE of URL "file:///Users/richmond/Desktop/Hax 8 March/AIW.txt" & " " after fld "fINPUT"
add 1 to LYNE
end repeat
end mouseUp
https://richmondmathewson.owlstown.net/
-
- Posts: 285
- Joined: Thu Sep 16, 2021 1:40 pm
- Contact:
Re: Answering Questions from elsewhere #1: Reading and writing text to / from a file
isn't it just this?
if the number of lines changed then you could doon mouseUp
answer file "Select a Huge File Greater than 200 Lines"
if it is empty then exit mouseUp
put "file:" & it into tOriginalFilePath
put line 1 to 200 of URL tOriginalFilePath into LinesToChange
--- changing case of first 200 lines as a test
--- and shoving them right back where we got them
put toUpper(LinesToChange) into line 1 to 200 of URL tOriginalFilePath
end mouseUp
and if you don't want to lose file in event of ...issues and assuming the file has standard 3 char extensionput number of lines of LinesToChange into tLinesChangedOffset
put toUpper(LinesToChange ) &cr& line tLinesChangedOffset to -1 of URL tOriginalFilePath into URL tOriginalFilePath
put char 1 to -5 of tOriginalFilePath &"_BackUp" & char 4 to -1 of tOriginalFilePath into BackUpPath
revcopyFIle tOriginalFilePath to BackUpPath
- richmond62
- Posts: 4833
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Answering Questions from elsewhere #1: Reading and writing text to / from a file
Not completely, as the OP wants to be able to read the first 200 lines.isn't it just this?
Mind you:
Could mean they want to load lines 1 - 200 into a field.I only need to read roughly the most recent 200 rows until something is true
HOWEVER, it could mean that they just want to do a spot of pattern matching.
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4833
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Answering Questions from elsewhere #1: Reading and writing text to / from a file
At this point:
- -
This script bottles out after the first appearance of the search term.
- -
Code: Select all
on mouseUp
put empty into fld "fRESULT"
put 1 into LYNE
repeat until LYNE > 200
put line LYNE of URL "file:///Users/richmond/Desktop/Hax 8 March/AIW.txt" into XYZ
if XYZ contains "MARMALADE" then
put "line" && LYNE && "contains 'MARMALADE'." into fld "fRESULT"
add 400 to LYNE
end if
add 1 to LYNE
end repeat
end mouseUp
https://richmondmathewson.owlstown.net/
-
- Posts: 442
- Joined: Sat Sep 11, 2021 4:37 pm
- Contact:
Re: Answering Questions from elsewhere #1: Reading and writing text to / from a file
Every time a URL reference is obtained the entire contents of the file are read from disk.
Klaus reminded the readers "over there" of that.
In your example, you should see a noticeable speed boost by reading the file only once, and then iterating its contents from a variable.
Side question: how is this conversation of such specific relevance to OXT to merit splitting the thread into a separate subthread here?
Klaus reminded the readers "over there" of that.
In your example, you should see a noticeable speed boost by reading the file only once, and then iterating its contents from a variable.
Side question: how is this conversation of such specific relevance to OXT to merit splitting the thread into a separate subthread here?
- richmond62
- Posts: 4833
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Answering Questions from elsewhere #1: Reading and writing text to / from a file
It isn't: you are missing the point:how is this conversation of such specific relevance to OXT to merit splitting the thread into a separate subthread here?
viewtopic.php?t=957
viewtopic.php?t=964
https://richmondmathewson.owlstown.net/
- richmond62
- Posts: 4833
- Joined: Sun Sep 12, 2021 11:03 am
- Location: Bulgaria
- Contact:
Re: Answering Questions from elsewhere #1: Reading and writing text to / from a file
Later on it became obvious the OP wanted to read from the end of their list, not the start . . .
https://richmondmathewson.owlstown.net/
-
- Posts: 442
- Joined: Sat Sep 11, 2021 4:37 pm
- Contact:
Re: Answering Questions from elsewhere #1: Reading and writing text to / from a file
Agreed: I've read both of those, and I still don't see the point.richmond62 wrote: ↑Sat Mar 09, 2024 10:53 amIt isn't: you are missing the point:how is this conversation of such specific relevance to OXT to merit splitting the thread into a separate subthread here?
viewtopic.php?t=957
viewtopic.php?t=964
Nevermind. Carry on...
- OpenXTalkPaul
- Posts: 2633
- Joined: Sat Sep 11, 2021 4:19 pm
- Contact:
Re: Answering Questions from elsewhere #1: Reading and writing text to / from a file
Does using a URL, as opposed to some other data container, read the whole file from disk/net into memory?
I'm not sure that it does, unless you pass it to another handler (without using the '@', pass by reference symbol).
I'm not sure that it does, unless you pass it to another handler (without using the '@', pass by reference symbol).
Who is online
Users browsing this forum: No registered users and 2 guests