I like that method of hitting both files at once, but i think you ment to say
if $istok($read(myfile.txt,nw,%var,1) $read(myotherfile.txt,nw,%var,1),%var,32) { echo -a %var matched as first word in one of the files }
Nope, he said he wanted to get the first word in the file, and if the assumption is that 1 line is 1 word, then $read(myfile.txt,n,1) simply returns this first word, no need for wildcards.
In that case maybe would be better, (second $read not being invoked if first $read == %var)
if ((($read(myfile.txt,nw,%var,1) == %var) || ($read(myotherfile.txt,nw,%var,1) == %var)) { echo -a %var matched as first word in one of the files }
This is true of course, I thought about that pretty instantly afterwards, though seeing as I told him he should store his text file in memory (hidden win/htb) it didn't seem worth it to mention anymore.
ok this sounds corny but Some Yahoo deletes the hidden window or kills the hashtable, this is scriptable around of course
This goes for anything, that yahoo might just delete the file as well when it sees this file which doesn't belong to him, but generated by a script. It'll actually be harder to delete the hidden window, since the person is never aware of it, unless they look in the window list, and issue a /close -@ @mywin or /window -c @mywind or a variation to that. Deleting a file is only a mouse click away.
As for the rest, I entirely disagree, let's compare file access to hash table/hidden win access:
FOR READING
//write -c test.txt test
//hadd -m test test test
//window -h @test | aline @test test
alias bench1 {
var %a = 50000, %b = $ticks
while %a {
.echo -q $read(test.txt,n,1)
dec %a
}
echo -s time taken reading from file: $calc($ticks - %b)
}
--> time taken reading from file: 8953 (1st time), 9796 (second time)
alias bench2 {
var %a = 50000, %b = $ticks
while %a {
.echo -q $hget(test,test)
dec %a
}
echo -s time taken reading from hash table: $calc($ticks - %b)
}
--> time taken reading from hash table: 1313 (1st time), 1328 (2nd time)
alias bench3 {
var %a = 50000, %b = $ticks
while %a {
.echo -q $line(@test,1)
dec %a
}
echo -s time taken reading from hidden window: $calc($ticks - %b)
}
---> time taken reading from hidden window: 1313 (1st time), 1328 (2nd time)
Quite funny how I got identical results for a hidden window and a hash table. I assume this is because it's only 1 data item in the htb, whereas htb's real advantage is reading from a large amount of data. Also the read from the hidden window is always the first line, so no seeking is involved.
There's a huge difference in accessing speed. Did my OS really cache that file to memory? I'd need to have some file monitoring program. Even if it did, the structure of a hash table is much better suited for data storage/retrieval, than a text file. Even doing a $line(@mywin,1) is much much faster than a $read(myfile.txt,n,1).
FOR WRITING
File handling commands don't count, since sparta's code also doesn't deal with an open file, it deals with a closed file.
alias bench4 {
var %a = 50000, %b = $ticks
while %a {
write test.txt test
dec %a
}
echo -s time taken writing to file: $calc($ticks - %b)
}
--> time taken writing to file: 14719
alias bench5 {
var %a = 50000, %b = $ticks
while %a {
aline @test test
dec %a
}
echo -s time taken writing to hidden window: $calc($ticks - %b)
}
--> time taken writing to hidden window: 2922
...