Invalid parameters: $regsubex (line 128, aliases.ini)
edit: i wonder if it may have to be with the fact that $regsubex is mentined in the file versions.txt.
Exactly. $read(file.txt,5) (for example) returns the 5th line in a file, but after evaluating its contents. Thus any variables/identifiers in the line will be evaluated. To prevent that, you can use the n switch: $read(file.txt,
n,5).
it only counted 20 chars and stopped, as there is a blank line after the first line. It seems that $read is not true for a blank line even though it is a line of a larger file.
Correct. An empty string (ie $null) in an if/while condition in mirc is considered FALSE. One way around that for this case is what you already did before with while (%i <= $lines($1.txt)). Another would be to also check $readn, which returns the line number of the last $read() call. Even if the line was blank and $read() returned $null, $readn would be filled with the non-zero line number, so you could check that.
i also noticed that using a while loop on a file with 1153 lines gave a slighly different result when using the /filter. I wonder if a loop loops to many times it loses count.
No, loops loop exactly as many times as you tell them
Regarding the different word count in hixxy's alias, I can't see why that happens in this case. The theory of long lines doesn't seem to apply here because $read() should agree with hixxy's alias (not with mine) and both should be giving a
larger word count than mine.
About the slow performance of the $read() approach, this is happening for two reasons:
1. Each $read(file.txt,N) call makes mirc
- Open the file
- Scan through the file starting from the beginning until it finds the Nth line
- Close the file
The second step above is what takes the most time of course. Looping through a 5-line file would make mirc consider 1+2+3+4+5 = 15 lines. For an N-line file in general, mirc considers N(N+1)/2 lines, so thousands become millions.
2. Having $lines() inside the while condition makes mirc evaluate $lines() over and over again. As mirc again has to go through all lines to find how many there are, this can get slow. To get around that, simply calculate the number of lines once and store the result, ie instead of this:
var %counter = 1, %wordcount
while (%counter <= $lines($1.txt))
you could do this:
var %counter = 1, %wordcount, %lines = $lines($1.txt)
while (%counter <= %lines)
hixxy's approach with /filter is much faster because /filter opens the file once, goes through it line by line (each line is considered only once), then closes the file.
My method is even faster because no external alias is called for each line: all counting is done "internally". Even though it may
look slower (as a temporary file is written and then deleted), the time saved by avoiding repeated alias calls is greater than the one spent in writing the temp file. Generally, keep in mind that mirc's internal routines are extremely fast ( mirc is written in C++) but its scripting routines are much slower. So whenever you have a choice between using a single mirc command for something and using a bunch of aliases or a while loop, choose the former.