/hashfile/$hashfile

By Serpentsounds on Feb 07, 2010

I originally made this to support something else I was making, when I said to myself, "it sure would be nice if I could use php's file() here." So, I decided to make my take on it, and I end up adding some things. Basic usage:

/hashfile FILE_NAME HASH_TABLE_NAME [START] [END]
$hashfile(FILE_NAME,HASH_TABLE_NAME,[START],[END]).DELIMITER

You can call it using either, and there isn't any difference unless you specify the delimiter property. The command will open the file name, and read each line into a new hash table item (named 0, 1, 2, etc).

If you specify the START parameter (don't use the brackets, that was to show it was optional), then reading will begin at that line. The items will still be named starting from 0, though. If you also specify END, then reading will stop at that line. If you specify START but not END, then it will read from START to the end.

If you are using it as an identifier, then you can specify DELIMITER as a property. What this does is, after it has reading into the hash table, it will concatenate all items into a string (with items separated by DELIMITER). DELIMITER should be the ASCII number of the character you wish to separate the items (for example, 32 for space). The string is then the return value of the identifier. If you do this, the hash table will be cleared afterwards.

This is kind of a niche-script, but if you happen to have such a niche, you're in luck!

alias hashfile {
  var %x 0,%y 0,%l $lines($1),%f $+(hashfile,$rand(1,32627))
  hmake $2 $calc(%l / 10)
  .fopen %f $1
  if ($3 isnum $+(0,-,$4)) && ($4 isnum $+($3,-,%l)) var %y $3,%l $4
  elseif ($3 isnum $+(0,-,%l)) && ($!4) var %y $3
  if (%y > 0) {
    var %z 1
    while (%z < %y) {
      noop $fread(%f)
      inc %z
    }
  }
  while (%y <= %l) {
    hadd $2 %x $fread(%f)
    inc %y
    inc %x
  }
  .fclose %f
  if ($prop isnum 0-255) {
    var %x 0,%str
    while ($hget($2,%x)) {
      var %str $+(%str,$chr($prop),$v1)
      inc %x
    }
    var %str $mid(%str,2)
    hfree $2
    return %str
  }
  return
  :error
  echo $color(Info text) -a * /hashfile: $error
  reseterror
}

Comments

Sign in to comment.
gooshie   -  Feb 07, 2010
echo -ac INFO * /hashfile: $error
 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.