zoukankan      html  css  js  c++  java
  • Tcl之group arguments

    1  doubel quotes

      This allows substitutions to occur within the quotations - or "interpolation". The substituted group is then evaluated as a single argument.

    puts "The current stock value is $varName" 

      In general, the backslash () disables substitution for the single character immediately following the backslash. Any character immediately following the backslash will stand without substitution.

      The final exception is the backslash at the end of a line of text. This causes the interpreter to ignore the newline, and treat the text as a single line of text. The interpreter will insert a blank space at the location of the ending backslash.

     1 set Z Jinan
     2 set Z_LABEL "The Capitol of Shandong is: "
     3 
     4 puts "$Z_LABEL $Z"   ;# Prints the value of Z
     5 puts "$Z_LABEL $Z"  ;# Prints a literal $Z
     6 
     7 puts "
    Ben Franklin is on the $100.00 bill"
     8 
     9 set a 100.00
    10 puts "Washington is not on the $a bill"    ;# This is not what you want
    11 puts "Lincoln is not on the $$a bill"      ;# This is OK
    12 puts "Hamilton is not on the $a bill"     ;# This is not what you want
    13 puts "Ben Franklin is on the $$a bill"    ;# But, this is OK
    14 
    15 puts "
    ................. examples of escape strings"
    16 puts "Tab	Tab	Tab"
    17 puts "This string prints out 
    on two lines"
    18 puts "This string comes out
    19 on a single line"

    2  braces

      Double braces disables substitution within braces. Characters within braces are passed to a command exactly as written.

      The only "Backslash Sequence" that is processed within braces is the backslash at the end of a line. This is still a line continuation character.

     1 set Z Albany
     2 set Z_LABEL "The Capitol of New York is: "
     3 
     4 puts "
    ................. examples of differences between  " and {"
     5 puts "$Z_LABEL $Z"
     6 puts {$Z_LABEL $Z}
     7 
     8 puts "
    ....... examples of differences in nesting { and " "
     9 puts "$Z_LABEL {$Z}"
    10 puts {Who said, "What this country needs is a good $0.05 cigar!"?}
    11 
    12 puts "
    ................. examples of escape strings"
    13 puts {There are no substitutions done within braces 
     
     x0a f v}
    14 puts {But, the escaped newline at the end of a
    15 string is still evaluated as a space}

    3  square brackets

      We obtain the results of a command by placing the command in square brackets ([]). This is the functional equivalent of the back single quote (`) in sh programming, or using the return value of a function in C.

      As the Tcl interpreter reads in a line it replaces all the $variables with their values. If a portion of the string is grouped with square brackets, then the string within the square brackets is evaluated as a command by the interpreter, and the result of the command replaces the square bracketed string.

      The exceptions to this rule are as follows:

      1)  A square bracket that is escaped with a is considered as a literal square bracket.

      2)  A square bracket within braces is not modified during the substitution phase.

     1 set x abc
     2 puts "A simple substitution: $x
    "
     3 
     4 set y [set x "def"]
     5 puts "Remember that set returns the new value of the variable: X: $x Y: $y
    "
     6 
     7 set z {[set x "This is a string within quotes within braces"]}
     8 puts "Note the curly braces: $z
    "
     9 
    10 set a "[set x {This is a string within braces within quotes}]"
    11 puts "See how the set is executed: $a"
    12 puts "$x is: $x
    "
    13 
    14 set b "[set y {This is a string within braces within quotes}]"
    15 # Note the  escapes the bracket, and must be doubled to be a
    16 # literal character in double quotes
    17 puts "Note the \ escapes the bracket:
     $b is: $b"
    18 puts "$y is: $y"
  • 相关阅读:
    康威定律和系统设计——《微服务设计》读书笔记
    安全——《微服务设计》读书笔记
    监控——《微服务设计》读书笔记
    测试——《微服务设计》读书笔记
    [转]Linux 系统挂载数据盘
    部署:持续集成(CI)与持续交付(CD)——《微服务设计》读书笔记
    拆分:分解单块系统——《微服务设计》读书笔记
    Unused Method(不再使用的方法)——Dead Code(死亡代码)
    使用Fortify进行代码静态分析(系列文章)
    NEUACM1132: Renew MST Quickly 增量最小生成树
  • 原文地址:https://www.cnblogs.com/mengdie/p/4608872.html
Copyright © 2011-2022 走看看