Code:
  if ($1 == !listall) {
    var %i = 1
    var %lines = $lines(learnt.txt)
    var %result
    while (%i <= %lines) {
      var %line = $read(learnt.txt,%i)
      var %islocation = $findtok(%line,=>,1,32)
      var %keyword = $gettok(%line,1- $+ $calc(%islocation -1),32)
      if (%result) { %result = %result $+ , %keyword }
      else { %result = %keyword }
      inc %i
    }
    msg $chan %result
  }


Explained:
if ($1 == !listall) {
if first word equals !listall

var %i = 1
create temporary variable %i equaling 1 (needed for the loop below)

var %lines = $lines(learnt.txt)
create temporary variable %lines which returns the total lines in the learnt.txt file
for this sample lets say %lines equals 12

var %result
create temporary variable %result for use later on

while (%i <= %lines) {
whileloop if %i (1) is less than or equal to %lines (12)

var %line = $read(learnt.txt,%i)
create temporary variable %line having it read learnt.txt line %i (1) to start

var %islocation = $findtok(%line,=>,1,32)
create temporary variable %islocation to get the location of =>

var %keyword = $gettok(%line,1- $+ $calc(%islocation -1),32)
create temporary variable %keyword to return just the keyword of the %line + %islocation results. Returns "word" and not "word =>"

if (%result) { %result = %result $+ , %keyword }
if %result is true/is something/not empty/etc... update the variable with the information it already has plus the new %keyword

else { %result = %keyword }
else if %result is false/is nothing update %result with %keyword

inc %i
increase the variable %i plus 1, %i was 1 now it's 2
the loop then goes back to the start and performs the same routine replacing %i = 1 with %i = 2

}
msg $chan %result
when the loop is completed message active channel the results
}

results will show as follows:
<nick> this entry, apple, grey matter, red, spoon, PIM, word, words, ammo, pistol

now to create the !last num thing


We don't just write the scripts, we put them to the test! (ScriptBusters)