Something similar to $read it will just allow faster reading and/or just memory usage without opening the file over and over again for reading a single line.
Example: /filetomem versions.txt
-> $readmem(versions.txt,1)
Would do the same as $read(versions.txt,n,1)
Example2:
$readmem(versions.txt,1) $readmem(versions.txt,2) $readmem(versions.txt,3)
This won't open/close the file over and over again like "$read(versions.txt,n,1) $read(versions.txt,n,2) $read(versions.txt,n,3)" would do.
Well uhm you could also use $fread etc. to this but it would also parse the file over and over again.
This snippet is just here to avoid double reading from a file.
alias readmem {
if ($isid) {
!var %hashname = $nopath($shortfn($1))
if (!$hget(%hashname,0).item) {
filetomem $shortfn($1)
}
if (!$hget(%hashname)) { return }
if (e isincs $2) {
!var %eval = $true
!tokenize 255 $1 $+ ÿ $+ $3-
}
if ($2 !isnum) && (!$len($2)) {
!var %result = $hget(%hashname,$r(1,$hget(%hashname,0).item)).data
if (%eval) { !return $(%result,2) }
else { !return %result }
}
elseif ($2 isnum) {
!var %result = $hget(%hashname,l [ $+ [ $2 ] ])
if (%eval) { !return $(%result,2) }
else { return %result }
}
}
else {
; It's an identifier ;p
}
}
alias filetomem {
var %hashname = $nopath($shortfn($1-))
if (!$hget(%hashname)) {
!hmake %hashname $lines($1-)
}
else {
!hfree %hashname
!hmake %hashname $lines($1)
}
if (!$exists($1-)) { !return }
!var %x = 0,%l = $lines($1-)
while (%x < %l ) {
!inc %x
!hadd %hashname l [ $+ [ %x ] ] $iif($read($1-,n,%x),$v1,$null)
}
}