• ACL is Arbortext’s Command Language. It is similar to Perl, which I really like. See Part 1 and Part 2.

    Variables

    A variable is a keyword or phrase that is linked to a “value” stored in memory or an expression that can be evaluated. For instance, a variable might be called “total_count” and contains a number. Variables are usually defined in ACL beginning with a dollar sign ($), they do not have to, but it is very good practice. The variable is on the left side and the value is on the right of the assignment operator (=). When assigning variables, it best to read right to left.  For example, assigning the string or text, “red” with the equal sign (=), to a variable “color”. It is a good practice to end your assignments with a semi-colon (;).

    $color = red;

    Some common variable assignments using expressions.

    #— Machine Name
    $machine = $main::ENV[‘COMPUTERNAME’];

    #— User’s Name
    $user = username();

    Variable Scope

    Variables exist in two locations or scopes, Global and Local.

    The default is Local. It is a good practice to define the minimum amount of scope needed or limiting your variables. This is helpful in maintaining the code and debugging it. For example, it may be confusing if a variable is a Global $A and a Local variable called $A are both being used in a For-Each loop.

    Global variables are accessible anywhere in the ACL code.

    Tip: If defining a Global Variable, pick a naming convention such as all caps. This will be helpful when mixing Local and Global variables in code. For Local variables, choose, for example, Camel Case.

    global $DEBUG = 1;
    local $UserName ="Tester";

    Local variables can be limited by a block of code (code inside the { }). When variables are assigned, inside blocks are local or limited just to that block. Blocks can be found in functions and items inside conditionals, such as an if statement.

    function findTMnumberName () {
       mark -select end
       $tmname = $selection #local variable
       gsub(‘^P’, $tmname);
       gsub(‘^V’, $tmname);
       $TMnumber = $TM_NAME[$tmname]; #local variables, global $TM_NAME
       response($TMnumber);
       caret 0,"<title>" -t
       is -pd "$TMnumber";
    }

    Shortcut Assignments

    If using a number variable as a counter, and the counter needs to increment by one, you could do:

    $lineNumber = $lineNumer +1;

    A shortcut using the (+=) means increment and assign the value to itself.

    $lineNumber += 1;

    If using a string variable using the dot operator (.) to concatenate or stitch together strings.

    $message = "File " . doc_name() . " sent to be published!";

    The variable $message resolves as “File Chapter 2 sent to be published!” if doc_name() was equivalent to “Chapter 2″.

    Variable Evaluation

    Variables inside double quotes will be evaluated, and variables inside single quotes are not evaluated.

    $username = "Tester";
    $message = "Hello $username!";

    Returns “Hello Tester!”

    $username = "Tester";
    $message = ‘Hello $username!’;

    Returns “Hello $username!”

    Comparative

    Using variables for comparison. In a “if” statement, you may want the variable, if true, then do something with it. Comparisons can be strings equaling or not equaling other strings. As well as, numbers equaling (==), not equaling (!=), greater (>), lesser (<), greater or equal (>=) or less than or equal (<=) to other numbers.

    String comparisons (==):

    if ($machine == "Dell")  {
       response("machine is a Dell");
    } else if (match($machine ,"HP*" )   {
       response("machine is not a Dell, but some HP Model");
    }

    Number comparison (==, >, <, !=, <=, >=)

    if  ($status !=0) {
        message "You must select something first”; #Not equal to zero
    }
    This entry was posted on Thursday, October 29th, 2009 at 2:38 pm and is filed under ACL, Structured Authoring. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
  • 3 Comments

    Take a look at some of the responses we have had to this article.

    1. Dec 11th

      Very Nice website. I built mine and i was looking for some ideas and your website gave me some. The website was developed by you?

      Cheers

    2. Dec 11th

      Thanks… The website is wordpress with a template called openair that I purchased from woothemes.

    3. Actually exciting thought for me . Will you publish some additional ? coz i desire to stick to ur twitter or facebook

  • Leave a Reply

    Let us know what you thought.

  • Name(required):

    Email(required):

    Website:

    Message: