Overview
 
The LookupFile and Lookup commands give Parse-O-Matic Scripting simple database capabilities:you can use a “key ” to look up an item of data..For example,a database of country abbreviations could look up 'US' (the “key ”)to find 'United States of America'(the “data ”).

The MassChange command can be used to apply search-and-replace edits to a line of data,based on the information contained in a Lookup file.

Lookup files can be prepared in a text editor program.You can name them anything you want,though by convention the file names start with Luf and have a .txt extension (example:LufCustomers.txt ).

The ScanFollow command provides a simple form of lookup capability that does not involve an external file.
 
Lookup
 
Parse-O-Matic Scripting supports several types of comparators:
 
Format v1 =Lookup v2 t3 [v4 ]
Examples MyVar =Lookup 'Car''MyTable';Find 'Car'in 'MyTable'table
Purpose .Looks up a value in a table read in from an external file
Parameters v1 -Variable being set (this is the “data ”)
v2 -Value being sought (this is the “key ”)
t3 -Table name (as defined by LookupFile)
v4 -Control setting
Controls IgnoreCase/MatchCase
Defaults v4 ='MatchCase'(v2 must match the table's key field exactly)
Similar Cmds SetFromFile
Notes Sets $Success ('Y'=v2 was found).
 
LookupFile
 
Here is a list of the literal comparators:
 
Format LookupFile t1 v2 [v3 [v4 [v5 ]]]
Examples LookupFile 'MyTable''C:\MyData \LufMyDatabase.txt'3 2
Purpose Reads in a table for use with the Lookup command
Parameters t1 -A name for this table (used by the Lookup command)
v2 -Name of the file being read in
v3 -Key field number (what you are looking for)
v4 -Data field number (what you find)
v5 –Control setting
Controls Decode/NoDecode
Defaults v3 =1
v4 =2
v5 =Decode
Restrictions LookupFile reads the entire table into memory.Thus,multi-
megabyte lookup files may cause problems on some machines.
(Comments are ignored,so you can use as many as you want
without affecting performance.)
Notes If the filename (v2)does not specify a path,LookupFile will
use the Search Path to look for it.
The sample lookup file LufSample01.txt (included with most Parse-O-Matic applications that feature end-user scripting)contains comments that explain the fundamental techniques you will need to define a lookup file.

Here is an example of a lookup file,named ScrSuppliers.txt :
;Lookup file for my suppliers,giving supplier number,name,and phone number
1,"Pinnacle Software","416-287-8892"
2,"Fred's Computers","514-555-1234"
3,"DigiRamaTech","212-555-4321"
This particular lookup file starts with a comment line.The data lines have three fields.You could look up the first field (the supplier number)to determine the supplier name or phone number.
The NoDecode control setting turns off the conversion of encoded text (e.g.$0D and #13).This is occasionally necessary when using a CSV (Comma Separated Value)file that does not put quotes around text fields.The default setting (Decode)will decode the string (see “Untypeable Characters ”).
 
MassChange
 
Format MassChange v1 t2 [v3 ]
Examples MassChange MyVar 'MyTable''IgnoreCase'
Purpose Applies every possible change listed in a Lookup file
Parameters v1 -The variable being changed
t2 -Table name (as defined by LookupFile)
v3 -Control setting
Controls IgnoreCase/MatchCase
Defaults v3 ='MatchCase'
Similar Cmds Change
 
MassChange is typically used for applying corrections to common typographical errors,rationalizing address
data (e.g.changing 'app.'to 'Apt.')or for remapping one character set to another one.

The sample lookup file LufSample01.txt (included with most Parse-O-Matic applications that feature
end-user scripting)contains comments that explain the fundamental techniques you will need to perform any
of these tasks.
 
ScanFollow
 
The Cut control setting removes the text that is found in the variable being examined,along with the encapsulating text. This technique is particularly useful when using a technique called “Left-Peeling ”. Consider the following script:
Format v1 =ScanFollow v2 v3 [v4 [v5 ]]
Examples X =ScanFollow 'C''/A/B/C/D/E';Set variable X to 'D'
Purpose Returns the next item in a character-delimited list
Parameters v1 -Variable being set
v2 -The value being sought in the list
v3 -The list (first character defines the list delimiter)
v4 -Value to return if v2 is not found or is last in the list
v5 -Control setting
Controls IgnoreCase/MatchCase
Defaults v4 =Null (empty)string
v5 =IgnoreCase
Similar Cmds Lookup
ScanFollow looks up a string in a list then returns the next string in the list.It can be used as a simple lookup tool,or to step through a series of strings.

If using ScanFollow as a lookup tool,remember that (unlike the Lookup command),ScanFollow does not distinguish between “key ” and “data ” — it simply finds the first occurrence of the value being sought and returns the next item in the list.

(This page is part of the online user manual for Parse-O-Matic.  Parse-O-Matic is a programmable parsing tool that can extract, manipulate, convert or mine existing data sources and turn them into importable data.  For more information on Parse-O-Matic products and conversion services, please visit www.ParseOMatic.com)