The characters matched to a pattern can be placed into a variable by using a colon (:) as an operator. The syntax of a variable assignment is:

         <variablename>:<pattern>
      

ASL assigns all of the characters that match the pattern to the variable. If the pattern does not match, the variable is not assigned a value.

To assign patterns that have more than one element, use braces to group the elements. All the components within the braces must successfully match before the variable is assigned a value. The syntax is:

         <variablename>:{<pattern_1>
         <pattern_2>
         <pattern_3>
         <pattern_4>}

The following script contains three variable assignments. The first and second variables are assigned the first and second word, respectively, in the datafile. The last variable is assigned an integer followed by two words.

This last variable demonstrates how patterns can be grouped by using braces. Without the braces, the variable is assigned only the integer.

The last name in the input file causes the pattern to fail because there is no address information.

ASL Script (assign_match.asl):
START {
 f_name:word l_name:word
 address:{integer word word}
 eol
}
do {
 print(f_name);
 print(l_name);
 print(address);
}
DEFAULT {
 ..eol
}
do {
 print("Failed match");
}
Input (assign_match.txt):
John Doe 11 Main St.
Jane Doe 35 Oak Dr.
Bill Jones
Output:
$ sm_adapter --file=assign_match.txt assign_match.asl
John
Doe
11 Main St.
Jane
Doe
35 Oak Dr.
Failed Match
$