Using Perl in Adaptive CLI

If you need conditional logic that goes beyond simple scripting, you can use Perl in Adaptive CLI. The example below checks to see if a String Attribute is empty (null) or not. If the String attribute (ShowCmdString) has content, the show command with ShowCmdString as a parameter goes to the device. Otherwise, the Perl script skips or excludes this statement.

Embedded CLI Example:

[IF ShowCmdString]

Show [ShowCmdString]

[ENDIF ShowCmdString]

You could use the CLI format for the above example, but if you need to check attributes of other types, besides String, then you must switch to Perl. For example:

Boolean myFlag equals True:

if ($myFlag)

{

     …

}

Integer myInt greater than zero:

Example:

if ($myInt > 0)

{

     …

}

To check whether a string is a particular value--like from a valid values list entry assigned to the String attribute--then you must also use Perl. The CLI format only can test if the String exists. It cannot validate its value when populated. For example: EncapsulationType = “VLAN-CCC”, “VLAN-TCC”, … You can not do this check with the CLI Format: [IF EncapsulationType = “VLAN-TCC”]. Instead, use a Perl script with a statement like this:

If ($EncapsulationType  eq  “VLAN-TCC”)

{

     print “set encapsulation $EncapsulationType\n”;

}

If any attributes in your script are a List (Collection), the only way to loop through the list’s items during the Adaptive CLI execution is to use Perl. For example: Processing a List of Strings:

$count = 0;

foreach @MyCommandList)

{

   print (“$MyCommandList[$count]\n”);

   $count++

}