$haddtok/$hremtok

By Pass on Sep 12, 2008

Description
These two aliases allow for greater hashtable manipulation by adding/removing specified text to/from a table item's data.

Uses
$haddtok(table,item,text,C) - Uses $addtok to add text into an item's data.
$hremtok(table,item,text,N,C) - Deletes (the Nth matching) text from an item's data using $remtok.

alias haddtok {
  if ($isid) hadd -m $1-2 $addtok($hget($1,$2),$3,$$4)
  else echo $color(info) * /haddtok syntax: $haddtok(table,item,text,C)
}
alias hremtok {
  if ($isid) {
      if ($hget($1,$2)) hadd $1-2 $remtok($hget($1,$2),$3,$4,$$5)
      else echo $color(info) * /hremtok: Error, no such $iif(!$hget($1),table,item) $iif($2,( $+ $2 $+ ))
   }
  else echo $color(info) * /hremtok syntax: $hremtok(table,item,text,N,C)
}

Comments

Sign in to comment.
Scakk   -  Sep 13, 2008

Never mind. Brain lapse.

 Respond  
Pass   -  Sep 13, 2008

Actually Scakk, the current order for $haddtok supports multiple words. The words are separated by commas, not spaces, so there's no need to change the order (it's as close as i could get to $addtok's syntax).

 Respond  
Scakk   -  Sep 13, 2008

I would redo the $haddtok as below.

alias haddtok {
  if ($isid) {
    hadd $iif(!$hget($1),-m) $1-2 $addtok($hget($1,$2),$4-,$3)
  }
}

New order would be --> $haddtok(Table,Item,C,Text)

1) Creates table if not created.
2) Allows entry of more than item into item.


Can shorten $hremtok to the below

alias hremtok {
  if ($isid) {
    if ( (!$hget($1)) || (!$hget($1,$2)) ) { echo -ag Error. No such $iif(!$hget($1), Table., Item.) }
    else { hadd $1-2 $remtok($hget($1,$2),$3,$4,$5) }
  }
}
 Respond  
Pass   -  Sep 13, 2008

It's been updated to incorporate the table creation. how's that, fellas?

 Respond  
^Neptune   -  Sep 13, 2008

Why not do a .make property so you can give more customization over it?

 Respond  
Pass   -  Sep 13, 2008

Yes, i left it out because i did not see the need for creating a table when the user would be trying to ADD data to a pre-existing table item (although, it would work). I feel as if it is personal preference, really.

 Respond  
Lindrian   -  Sep 13, 2008
    if ($hget($1)) hadd $1-2 $addtok($hget($1,$2),$3,$4)
    else echo $color(info) * /haddtok: Error, no such table $iif($1,( $+ $1 $+ ))

You can use the -m switch here, incase the table does not exist, it creates it.

 Respond  
Pass   -  Sep 12, 2008

Indeed, it is a time-saver if you use hashtables as much as myself

 Respond  
EL   -  Sep 12, 2008

Ima have to test it but it looks like it will come in handy.`-.-´

 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.