<< Click to Display Table of Contents >> Navigation: 3. Script Language > Filesystem-Commands > Filesystem-Commands |
MiniRobotLanguage (MRL)
LFT. - Line-From-Text
Line from Text File that was loaded into internal Buffer for faster processing
Intention
When doing "Line-based" Operations on a Textfile, the use of LFF. (Line from File) can become slow.
Therefore the Combination of LOF. and LFT. was made. These Command-Pair works "in Memory".
Therefore you can access any Line of the Textfile immediately without any harddrive access.
This can speed up any Text-Processing significantly.
Please also take a look at the TXT.-Commands. These Commands can be used, to save or change the Textfile.
LFT. only works together with LOF. So you need to "Load the Textfile" first using LOF. before you can use LFT.
Generally LFT. has two Working-Modes:
1. Get Line from FIle
LFT. with a number from 1 to (Number of Lines), will return the Line with that number in $$RET:
LFT.$$IND|$$NUM|$RET
2. Get number of Lines in FIle
LFT. with a number -1, will return the number of stored Lines from that file with that Index-Number.
LFT.$$IND|-1|$$RET
As you can not change the loaded file using LFT., there are two options in case you need to cahnge the file:
1. You can transfer the file to the TXT.-Command and work there. TXT. was designed specially for these tasks.
2. You can do this:
If you need to process the file, then the workflow is taht <ou read the Source-File using LOF. and LFT.
and write a changed version using ATF.- or CTF. - Command.
FInally you can "Switch the filenames" using the new FIL.Swap-Command.
If you call LFT. with a Number larger then the number of Lines in that File, the returned Variable will be empty.
Currently you can load up to 128 Textfiles into the Buffer at the same time, each having its own Index-Number from 1 to 128. This is very good if you need to work on multiple Text-Files at the same time, but you do not want to access the harddrive so often. Using LOF. the file is buffered and all further Operations using LFT. are done in memory.
Usage is simple:
VAR.$$FIL=?path\Test.txt
' Read the File into Memory
LOF.$$IND|$$FIL
'The Index Number for this file is now in $$IND
LFT.$$IND|-1|$$RET
'Using LFT. with " -1" as Linenumber, we get the Number of
'Lines in return (here in $$RET).
' Now we enumerate through the File without accessing
' the harddrive, at maximum Speed
FOR.$$LOP|1|$$RET
LFT.$$IND|$$LOP|$$LIN
PRT.$$LIN
NEX.
MBX.Ready
ENR.
Syntax
LFT.P1|P2[|P3]
Parameter Explanation
P1 - (Variable or number) In this Variable the Index of the File must
be specified. You receive the Index when you call the LOF.-Command.
P2 - Linenumber of the Line to read. If this is "-1" then the Number of Lines
in the referenced file is returned.
P3 - (Variable) In this Variable the result of the Operation is returned.
This is whether the Line from that file, or it is the number of lines in that file.
If omitted the result will be placed on TOS.
Example
'********************************************
' Demo for LOF and LFT.
'********************************************
VAR.$$FIL=?path\Test.txt
LOF.$$IND|$$FIL
PRT.The Index Number for this file is >$$IND<
LFT.$$IND|-1|$$RET
PRT.Using LFT. with " -1" we get the Number of Lines.
PRT.Which is $$RET.
' Now we enumerate through the File without accessing
' the harddrive, at maximum Speed
FOR.$$LOP|1|$$RET
LFT.$$IND|$$LOP|$$LIN
PRT.$$LIN
NEX.
MBX.Ready
ENR.
Remarks
The current Limitation is that you can not load more then 128 Textfiles at the same time into Memory.
Also the delimiters must be $crlf$. If that is not the case, the Text-Files may be automatically converted when they are loaded.
For example, if there are only $CR in a File that is loaded, the Loader will add a $LF to each $CR so that in the Buffer you have a $crlf$ delimited FIle.
Limitations:
Currently you can load up to 128 Textfiles into the Buffer at the same time, each having its own Index-Number from 1 to 128. This is very good if you need to work on multiple Text-Files at the same time, but you do not want to access the harddrive so often. Using LOF. the file is buffered and all further Operations using LFT. are done in memory.
You can not change the loaded file, this is the price for the speed that you get using this command-Pair.
If you need to make changes to the file, switch over to the TXT.-Command.
See also:
• IEF. / NEF. - If - exist - File