Answering to these in reverse order
bobcole wrote: ↑Sun Feb 23, 2025 7:25 pm
As the Original Poster (OP) said the issue is the size of the data file:
I actually trying to avoid repeat loop as my pc might not be able to handle 300-500 mb size data
Therefore, is there a way to read from the file one line at a time? I realize this will be slow in comparison to the alternatives posted above.
There are many many MANY ways to do it, and reading directly from the file is no worse in this case than any other. A simple way to find out what amount of time it would take for each method is to craft a simple timer, and put each of the various routines into a simple script which calls it before the routine starts, and stops it when the routine ends, subtract the start from the end, voila, you have the amount of time (in seconds) that each took. I'll leave that to the more eager of you out there
xoxiwe wrote: ↑Sun Feb 23, 2025 6:09 pm
So what I've learnt is, array thing is only possible when all the lines have the equal number of items, and subkeying with negative numbers isn't possible to start column counting from the last what is possible only in repeat loop.
This is not the correct lesson to take away. Arrays will work the same as any other programmatic variable/method will work, the correct lesson to take away from this small diversion is that your data needs to be consistent no matter what method you are using to extract it. The generic term that says it all is "...garbage in, garbage out".
In other words, if you have a line with 3 items, lets say index number, Name, and phone number, then every line that follows needs to have them in the same order, every time. Your example listed earlier as I pointed out has all the elements apparently jumbled around, you can not program in any way I know of to take that into an account. If line 1 looks like:
[indent]1, Joe James, 916-864-5789 [/indent]
... then line 2 can not alter that order, even as little as ...
[indent]James John, 2, 916-864-5789 [/indent]
or the results will look like the mess you are working with. The lines do need the same amount of delimiters in them, but even more importantly is that each item, whether missing or not, is in its correct
place in the line. Let's take line 1 thru 4 from your earlier example with my guess as to interpretation of the data:
I hope you see the problem clearer now. If you were trying to get the last 2 items of each line, and assumed those would be the email address and name (my guessing) or whatever they are in this example, you would have results that are not as you expect them to be because lines 2 and 4 do not have the data in the format lines 1 and 3 do, regardless of which method you used in code, because your "data" is all mixed up, even in just 4 lines.
The array on the other hand, would still have 7 keys in it, in order from 1 to 8. You could (in code) simply request keys 7 and 8 (the last 2 keys in the array) and put them into a field just as I showed up there, but the data you would see would NOT ALWAYS be the data you are looking for because your SOURCE DOES not have each item in it's place in the line.
--Edit -- I am of course making the assumption that the example list CAME from your source list, if that is not the case, you certainly could try it with the code provided and see what you get
