DCL Symbols

A DCL symbol is a symbolic name for a character string or integer. A symbol may be used in place of a literal value. For example, symbols may be used as a shorthand substitute for long command lines, or they may be used much like variables, as found in compiled programming languages.

Before we demonstrate the use of symbols, it is important to understand the two types of symbols: local and global.

Symbol Scope

The term scope refers to the context in which a symbol is recognized. A symbol with local scope has meaning only within a limited environment, but a symbol with global scope is recognized throughout the process.

A local symbol is one that is valid only for the current command level, whereas a global symbol is valid at any command level. When you log in, your process is at command level 0. If you execute a command procedure, the procedure is at command level 1. If that procedure executes another procedure, the second one will execute at command level 2. DCL supports up to command level 31; level 0 is the highest command level, and level 31 is the lowest. Command procedures are described in Chapter 9 "Command Procedures."

DCL maintains a separate table of local symbols for each command level. When a command level is ended, all of its local symbols are destroyed.

On the other hand, global symbols are active at all command levels in the process. A global symbol created or modified at any level is accessible by all levels. If a global symbol is created at any command level, the symbol endures even after the command level ends.

If a local symbol and a global symbol of the same name exist at a particular command level, the local symbol takes precedence. Each of these commands is described in the upcoming paragraphs:

     $ TOTAL = 15        ! Create a local symbol     $ TOTAL == 10       ! Create a global symbol of the same name     $ SHOW SYMBOL TOTAL ! The local symbol takes precedence       TOTAL = 15  Hex = 0000000F  Octal = 00000000017 

The next few paragraphs demonstrate the creation and use of some symbols.

Creating a Symbol

Use one of the following operators to create a symbol:

  • = creates a local character string or integer symbol.

  • := creates a local character string symbol.

  • == creates a global character string or integer symbol.

  • :== creates a global character string symbol.

The general format for creating a symbol is as follows:

     $ symbol_name [:=]= value_to_assign 

Specific examples of symbol creation are contained in the following sections.

Examining the Value of a Symbol

You may examine the value of an existing symbol using the SHOW SYMBOL command, such as in the following example:

     $ TOTAL = 10     $ SHOW SYMBOL TOTAL       TOTAL = 10   Hex = 0000000A  Octal = 00000000012     $ TEXT := "This is a character symbol"     $ SHOW SYMBOL TEXT       TEXT = "This is a character symbol" 

Integer symbols are displayed in decimal, hexadecimal, and octal representations.

Deleting a Symbol

Symbols may be deleted via the DELETE/SYMBOL command. Local symbols are assumed; the /GLOBAL qualifier is required to delete a global symbol:

     $ TOTAL == 10     $ SHOW SYMBOL TOTAL       TOTAL == 10   Hex = 0000000A  Octal = 00000000012     $ DELETE/SYMBOL/GLOBAL TOTAL     $ SHOW SYMBOL TOTAL     %DCL-W-UNDSYM, undefined symbol - check validity and spelling 

Using a Symbol in Place of a DCL Command

Certain DCL commands can be quite lengthy. To save keystrokes, symbols are often used in place of long or frequently used commands.

You may wish to use your LOGIN.COM file to create such symbols automatically when you log in. LOGIN.COM is described in Chapter 7, "The User Environment."

Let's say that your preferred EDIT command is as follows:

     $ EDIT/EDT/COMMAND=SYS$LOGIN:EDTINI.EDT 

Rather than typing such a long command over and over, you may define a short symbol to represent the entire command:

     $ EDT :== EDIT/EDT/COMMAND=SYS$LOGIN:EDTINI.EDT 

Once the symbol is assigned, you may use EDT in place of the complete command, treating it as if it were a command verb:

     $ EDT filespec 

Some users choose to redefine existing DCL verbs to apply the qualifiers they use most often automatically:

     $ PRINT :== PRINT/NOBURST/NOFLAG/NOTRAILER/NOTIFY 

After the above symbol assignment is made, the command PRINT automatically includes the qualifiers shown. If you would like to override any of the qualifiers, you may apply conflicting qualifiers to your command symbol. This example keeps all of the qualifiers associated with the symbol, but cancels the /NOTIFY qualifier:

     $ PRINT/NONOTIFY SCHEDULE.LIS 

The command above results in the following command being executed:

     $ PRINT/NOBURST/NOFLAG/NOTRAILER/NOTIFY/NONOTIFY SCHEDULE.LIS 

The resulting command effectively contains both /NOTIFY and /NONOTIFY, but DCL acts only on the latter (/NONOTIFY).

Be warned that Hewlett-Packard, like Compaq and Digital, recommends against defining symbols with names exactly matching existing command verbs. Many users do so anyway, accepting the undesirable effects, which consist mostly of confusion.

As an example of an undesirable effect of this practice, consider a command symbol from the author's LOGIN.COM:

     $ DEL*ETE :== DELETE/CONFIRM 

The author uses this symbol because he occasionally issues a DELETE command that deletes more files then he actually intended. To prevent such occurrences, he uses the symbol DEL*ETE (The asterisk denotes the length to which the symbol may be abbreviated) so that DELETE commands automatically include the /CONFIRM qualifier, which prompts for confirmation before deleting each file.

Usually, this causes no trouble at all. The problem arises when the author issues the DELETE/SYMBOL command. Since DCL does not consider DELETE/CONFIRM to be consistent with DELETE/SYMBOL, it issues a message that may confuse a user who does not know what is going on:

     $ DELETE/SYMBOL/GLOBAL PRINT     %DCL-I-IGNQUAL, qualifiers appearing before this item were ignored      \SYMBOL\ 

The command completes successfully, but DCL issues an informational message warning that the implicit /CONFIRM qualifier was ignored.

Also, if the author executes a command procedure containing DELETE commands and those commands do not explicitly include /NOCONFIRM, the command procedure pauses to ask for confirmation of each file deletion.

Many users believe that side effects such as these are a minor inconvenience compared with accidentally deleting important files.

Symbols as Character or Text Variables

Another common use for symbols is to store integer or text values.

Symbols are indispensable in command procedures, where they take the place of variables as found in a compiled programming language. Using symbols in this way is also supported directly at the DCL prompt.

Creating an Integer Symbol

To create an integer symbol, assign a value to it using "=" for a local symbol or "==" for a global symbol. This example creates a symbol called APPLES and assigns it a value of 10:

     $ APPLES = 10     $ SHOW SYMBOL APPLES       APPLES = 10   Hex = 0000000A  Octal = 00000000012 

Symbols may be used in mathematical calculations, as shown here:

     $ APPLES = 2 * (4+5)     $ SHOW SYMBOL APPLES       APPLES = 18   Hex = 00000012  Octal = 00000000022     $ !     $ ORANGES = 15     $ SHOW SYMBOL ORANGES       ORANGES = 15   Hex = 0000000F  Octal = 00000000017     $ !     $ TOTAL_FRUIT = APPLES + ORANGES     $ SHOW SYMBOL TOTAL_FRUIT       TOTAL_FRUIT = 33   Hex = 00000021  Octal = 00000000041 

The assignment of TOTAL_FRUIT was the result of adding the values of APPLES and ORANGES. DCL supports several integer arithmetic operators, which include the following:

  • + for addition or to denote a positive number

  • - for subtraction or to denote a negative number

  • * for multiplication

  • / for division

  • () to specify the order of mathematical operations

Creating Character String Symbols

As seen earlier, symbols can also represent text data. In our earlier example, a symbol was used to represent a DCL command. In addition, symbols may represent arbitrary text:

     $ COLOR = "blue"     $ SHOW SYMBOL COLOR       COLOR = "blue"     $ !     $ ! Character-string symbols may be manipulated or combined:     $ !     $ COLOR = "greenish-" + color     $ SHOW SYMBOL COLOR       COLOR = "greenish-blue" 

The example above first sets COLOR to "blue," and then changes it to "greenish-blue." Note that the symbol COLOR appears on both sides of the equals sign. The right-hand side of an expression is calculated first, and then the result is assigned to the symbol COLOR. This allows the new value of COLOR to depend on the old value. This is a common feature of many programming and scripting languages.

How Symbols Are Evaluated by DCL

Symbols are substituted (replaced by their values) automatically in the following circumstances:

  • On the right side of the =, ==, :=, and :==operators

  • In a lexical function (discussed later)

  • Within brackets on the left side of an assignment (for performing character or bit overlays, not covered in this book).

  • As the first element on a command line (in place of a DCL verb).

Should you need to force a symbol substitution in another circumstance, enclose it in single quotes:

     $ FILENAME = "login.com"     $ TYPE 'filename' ! the file LOGIN.COM will be typed 

If you need to force symbol substitution within a set of double quotes, use two leading single quotes and one trailing single quote:

 $ FILENAME = "login.com" $ TYPEIT = "TYPE ''filename'" 

A word of caution for the inexperienced user: Pay particular attention to the use of = or ==versus :=or :==to assign a value to a symbol. When assigning a symbol with the = or == operator, the value must be enclosed in quotes. Using := or :==allows you to omit the quotes and automatically converts the value to upper-case letters and compresses multiple spaces or tabs into one space. It also has some potentially frustrating effects, which are shown in the following example.

     $ !     $ ! The := or :== operator works with this syntax:     $ !     $ color = "blue"     $ color := "greenish-''color'"     $ show symbol color       COLOR = "greenish-blue"     $ !     $ ! But := or :== does not work as you might intend     $ ! with this syntax:     $ !     $ color = "blue"     $ color := "greenish-" + color     $ show symbol color       COLOR = "greenish-+ COLOR"     $ !     $ ! On the other hand...     $ !     $ ! The = or == operator behaves identically with either syntax:     $ !     $ color = "blue"     $ color = "greenish-" + color     $ show symbol color       COLOR = "greenish-blue"     $ !     $ color = "blue"     $ color = "greenish-''color'"     $ show symbol color       COLOR = "greenish-blue" 



Getting Started with OpenVMS(c) A Guide for New Users
Getting Started with OpenVMS: A Guide for New Users (HP Technologies)
ISBN: 1555582796
EAN: 2147483647
Year: 2005
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net