Is there a better and faster way of doing this. This snippet crashes if there are too many lines in the specifies text file.

Code:
alias read {
  if (!$isfile($$1 $+ .txt)) { echo -a error: file $$1 $+ . txt not found. | return }
  echo -a $timestamp Counting words of $$1 $+ .txt
  var %counter = 1, %wordcount
  while ($read($$1 $+ .txt,%counter)) {
    inc %wordcount $numtok($read($$1 $+ .txt,%counter),32)
    inc %counter
  }
  echo -a $timestamp The file $$1 $+ .txt has %wordcount words in it.
}