From WikiChip
Difference between revisions of "mirc/commands/hload"
< mirc‎ | commands

(Switches)
Line 1: Line 1:
 
{{mirc title|/hload Command}}
 
{{mirc title|/hload Command}}
The '''/load command''' loads a text file to an hash table. /hload does not create the table, it must already have been created by {{mIRC|/hmake}}.
+
The '''/load''' command loads a text file to an hash table. /hload does not create the table, it must already have been created by {{mIRC|/hmake}} then saved to disk using {{mIRC|/hsave}}.
 
 
 
== Synopsis ==
 
== Synopsis ==
  /hload -sbnimN <name> <filename> [section]
+
  /hload -sbnmN <name> <filename>
 
+
/hload -sinmN <name> <filename> [section]
 
== Switches ==
 
== Switches ==
* '''-b''' - loads binary files, {{mIRC|$cr}} and {{mIRC|$lf}} are preserved when saving as binary files
 
* '''-n''' - loads files as data only, each item is a number, starting at N = 1
 
* '''-i''' - treats the file as an ini file
 
 
* '''-s''' - display a message if successful: "* Loaded hash table '<name>' from '<filename>'
 
* '''-s''' - display a message if successful: "* Loaded hash table '<name>' from '<filename>'
* '''-mN''' - create the hash table if it does not exist, you can specify N for the number of bucket
+
* '''-b''' - loads binary files, {{mIRC|$cr}} and {{mIRC|$lf}} and 0x00's etc are preserved when saving as binary files
 
+
* '''-n''' - loads files as data only, each item is a sequential integer, starting at N = 1
 +
* '''-i''' - treats the file as an ini file format
 +
* '''-mN''' - create the hash table if it does not exist, you can optionally specify N for the number of buckets in the range 1-10000, default 100 if N not used.
 
== Parameters ==
 
== Parameters ==
 
* '''<name>''' - the name of the hash table
 
* '''<name>''' - the name of the hash table
* '''<filename>''' - the file you want to load from
+
* '''<filename>''' - the file from which you want to load. Filename containing space much be enclosed in doublequotes.
* '''[section]''' - if -i is used, you can specify a section to be loaded
+
* '''[section]''' - if -i is used, you can specify a section to be loaded. Default section name when parameter not used: hashtable (Should not use the square braces around the Section name.)
 +
== Notes ==
 +
* Note: /hload uses the same syntax as /hsave except /hload has the -mN switch but does not have /hsave's -u switch.
 +
* Note: If using /hload -i or -b or -n switches, it assumes the data was /hsave'ed to disk using those same switches.
 +
* Note: If /hload into a table containing existing items, any match between existing item name and the items loaded from disk replaces the existing item's value with the value from disk, but any other existing items in the table are not affected by an /hload command.
 +
== Example ==
 +
<source lang="mIRC">
 +
//hfree -w test | hload -im1n test $nopath($mircini) colors | var %tot $hget(test,0).item , %i 1 | while (%i <= %tot) { echo -a $ord(%i) item is $hget(test,%i).item containing $hget(test,$hget(test,%i).item) | inc %i }
 +
* Loads color scheme names and event colors into items named after the integers 1 and greater. These are contained in the colors section of mirc.ini. If the 'n' switch were not used, the item names would instead be named the same as the items in mirc.ini; n0 n1 etc.
 +
* If using the -n switch, do not expect the same values to be loaded into the same integer item names from which they were /hsave'ed to disk, even if using 1 bucket.
  
== Example ==
+
//hload -m test no_such_file | echo -a does not display
None
+
* Attempting to load a non-existent filename is an error which halts execution of the script.
  
 +
//bset &var 1 $regsubex($str(x,256),/x/gi,$calc(\n -1) $chr(32)) | hfree -w test | hadd -mb test ascii &var | hsave -b test test.dat | hload -mb test2 test.dat | noop $hget(test,ascii,&copy) | echo 4 -a $bvar(&copy,1-)
 +
* Binary variable can be accurately saved to a hashtable item, then /hsave'ed to disk with the -b switch, then /hload'ed from disk with the -b switch. The display shows &copy containing an un-altered copy of the original binary variable.
 +
</source>
 
== Compatibility ==
 
== Compatibility ==
 
Added: 5.8
 
Added: 5.8
 
 
== See also ==
 
== See also ==
* [[List of commands - mIRC|List of commands]]
+
{{collist
* [[List of identifiers - mIRC|List of identifiers]]
+
|count = 3
 +
|style = width: 60%; display: inherit;
 +
|
 +
* {{mIRC|/hmake}}
 +
* {{mIRC|/hfree}}
 +
* {{mIRC|/hsave}}
 +
* {{mIRC|Hash Tables}}
 +
* {{mIRC|/hadd}}
 +
* {{mIRC|/hdel}}
 +
* {{mIRC|/hinc}}
 +
* {{mIRC|/hdec}}
 
* {{mIRC|$hget}}
 
* {{mIRC|$hget}}
 
* {{mIRC|$hfind}}
 
* {{mIRC|$hfind}}
* {{mIRC|/hadd}}
+
}}
* {{mIRC|/hdec}}
 
* {{mIRC|/hinc}}
 
* {{mIRC|/hmake}}
 
* {{mIRC|/hsave}}
 
{{mIRC command list}}
 
 
 
[[Category:mIRC commands|hload command - mIRC]]
 

Revision as of 01:45, 17 June 2018

The /load command loads a text file to an hash table. /hload does not create the table, it must already have been created by /hmake then saved to disk using /hsave.

Synopsis

/hload -sbnmN <name> <filename>
/hload -sinmN <name> <filename> [section]

Switches

  • -s - display a message if successful: "* Loaded hash table '<name>' from '<filename>'
  • -b - loads binary files, $cr and $lf and 0x00's etc are preserved when saving as binary files
  • -n - loads files as data only, each item is a sequential integer, starting at N = 1
  • -i - treats the file as an ini file format
  • -mN - create the hash table if it does not exist, you can optionally specify N for the number of buckets in the range 1-10000, default 100 if N not used.

Parameters

  • <name> - the name of the hash table
  • <filename> - the file from which you want to load. Filename containing space much be enclosed in doublequotes.
  • [section] - if -i is used, you can specify a section to be loaded. Default section name when parameter not used: hashtable (Should not use the square braces around the Section name.)

Notes

  • Note: /hload uses the same syntax as /hsave except /hload has the -mN switch but does not have /hsave's -u switch.
  • Note: If using /hload -i or -b or -n switches, it assumes the data was /hsave'ed to disk using those same switches.
  • Note: If /hload into a table containing existing items, any match between existing item name and the items loaded from disk replaces the existing item's value with the value from disk, but any other existing items in the table are not affected by an /hload command.

Example

//hfree -w test | hload -im1n test $nopath($mircini) colors | var %tot $hget(test,0).item , %i 1 | while (%i <= %tot) { echo -a $ord(%i) item is $hget(test,%i).item containing $hget(test,$hget(test,%i).item) | inc %i }
* Loads color scheme names and event colors into items named after the integers 1 and greater. These are contained in the colors section of mirc.ini. If the 'n' switch were not used, the item names would instead be named the same as the items in mirc.ini; n0 n1 etc.
* If using the -n switch, do not expect the same values to be loaded into the same integer item names from which they were /hsave'ed to disk, even if using 1 bucket.
 
//hload -m test no_such_file | echo -a does not display
* Attempting to load a non-existent filename is an error which halts execution of the script.
 
//bset &var 1 $regsubex($str(x,256),/x/gi,$calc(\n -1) $chr(32)) | hfree -w test | hadd -mb test ascii &var | hsave -b test test.dat | hload -mb test2 test.dat | noop $hget(test,ascii,&copy) | echo 4 -a $bvar(&copy,1-)
* Binary variable can be accurately saved to a hashtable item, then /hsave'ed to disk with the -b switch, then /hload'ed from disk with the -b switch. The display shows &copy containing an un-altered copy of the original binary variable.

Compatibility

Added: 5.8

See also