title: Tcl: default if variable is empty?
body: <p>I've "inherited" some Tcl code, and while I worked through some tutorials and can make sense out of the language, my own Tcl constructs lack a certain... finesse.</p>
  
  <p>For example, I have this code:</p>
  
  <pre><code>puts "Column 'name': [ $queryRs getString name ]"
  </code></pre>
  
  <p><code>$queryRs</code> is the result set of a SQL query. The <code>[ $queryRs getString name ]</code> construct retrieves the content of the table column "name" from the current row in the result set. If the database field is NULL, the <code>puts</code> does not print anything.</p>
  
  <p>I would like to print a "default" string instead, i.e. if <code>[ $queryRs getString name ]</code> results in nothing, I'd like to replace it with <code>"--"</code>.</p>
  
  <p>Now, I could do something like this:</p>
  
  <pre><code>set nameVar "[ $queryRs getString name ]"
  if { [ string length $nameVar ] == 0 } {
      set nameVar "--"
  }
  puts "Column 'name': $nameVar"
  </code></pre>
  
  <p>But there <strong>has</strong> to be a more compact solution, something that can be done inline instead of adding four lines and a temporary variable. Help, please?</p>