{"id":103,"date":"2008-04-24T22:44:29","date_gmt":"2008-04-24T17:14:29","guid":{"rendered":"http:\/\/www.bin-co.com\/blog\/?p=103"},"modified":"2008-04-24T22:44:29","modified_gmt":"2008-04-24T17:14:29","slug":"hello-script-for-tcl","status":"publish","type":"post","link":"https:\/\/www.bin-co.com\/blog\/2008\/04\/hello-script-for-tcl\/","title":{"rendered":"Hello Script for Tcl"},"content":{"rendered":"<p><img src='http:\/\/www.bin-co.com\/images\/tcl.gif' alt='Tcl Logo' align=\"right\" \/><\/p>\n<p class=\"intro\"> <a href=\"http:\/\/www.tcl.tk\/\">Tcl, or Tool Command Language<\/a>, will not be found in the &#8216;most popular languages&#8217; hall of fame. That is partly because of its &#8216;wierd&#8217; syntax. But those who know Tcl will tell you that Tcl is a pleasure to work with. I have a special interest in Tcl &#8211; its the language that introduced me to GUI programming(<a href=\"http:\/\/www.bin-co.com\/tcl\/\">Tcl\/Tk<\/a>). Now, when ever I see a GUI toolkit, I <a href=\"http:\/\/www.bin-co.com\/blog\/2007\/10\/tk-verses-gtkand-python-verses-tcl\/\">compare it to Tcl<\/a>.<\/p>\n<p>I have a few years experience in Tcl &#8211; I have written a very popular <a href=\"http:\/\/www.bin-co.com\/tcl\/tutorial\/\">Tcl\/Tk Tutorial<\/a> and also a <a href=\"http:\/\/www.bin-co.com\/tcl\/scripts\/indexer\/\">few<\/a> <a href=\"http:\/\/www.bin-co.com\/tcl\/scripts\/ri\/\">small<\/a> <a href=\"http:\/\/www.bin-co.com\/tcl\/scripts\/tagview\/\">applications<\/a> in Tcl. I am not using it a lot now a days because Tk apps look really bad in Linux. This problem is not present in Windows.<\/p>\n<h3>Hello Code<\/h3>\n<pre><code class=\"tcl\">\n#!\/usr\/bin\/tclsh\n\n# Printing(IO)\nputs \"Hello World!\\n\" \n\n# Variables, concatenation\nset name 'Binny' \nset year 2008 \nputs [concat \"Hello, \"  $name  \" - welcome to \"  $year]\n\n#If,else conditions\nif { $year &gt; 2008 } {\n\t puts \"Welcome to the future - yes, we have flying cars!\" \n\n} elseif { $year &lt; 2008 }  {\n\t puts \"The past - please don't change anything. Don't step on any butterflies. And for the sake of all that's good and holy, stay away from your parents!\" \n\n} else {\n\t puts \"Anything wrong with your time machine? You have not gone anywhere, kiddo.\" \n}\n\n# For loop\nfor { set i 0 } { $i&lt;3 } { incr i  }  { \n\t puts \"$i) Hi there!\" \n}\n\n#Numerical Array, foreach\nset rules [list \"Do no harm\" \"Obey\" \"Continue Living\"]\n\nset i 0\nwhile { $i &lt; [llength $rules] } {\n\tputs [concat \"Rule \" [expr $i+1] \" : \"  [lindex $rules $i]]\n\tincr i \n}\n\n# Associated array, while\narray set associated {\n\thello\t\"world\"\n\tfoo\t\t\"bar\"\n\tlorem\t\"ipsum\"\n}\n\nforeach key [array names associated] {\n\t puts [concat $key \" : \" $associated($key)]\n}\n\n# Using Join and Split\nset csv_values [split \"hello,world,how,are,you\\n\" \",\"]\nputs [join $csv_values \":\"]\n\n# Function, argument, return, call\nproc hello { person_name } {\n\treturn [concat \"Hello, \" $person_name]\n}\nputs [hello \"Binny\"]\n\n# File IO\n# File reading, easy method...\nset IN [open \"Hello.tcl\" r]\nset contents [read $IN]\nclose $IN\nputs [concat \"Hello has \" [string length $contents] \" chars\"]\n\n# Writing to a file\nset OUT [open \"\/tmp\/hello.txt\" w]\nputs $OUT \"Hello World\"\nclose $OUT\n\n# Regular Expressions\nset str \"Hello World\" \nif { [regexp {^Hell} $str] } {\n\tputs \"Yup, its evil\"\n}\n\nputs [regsub -all {l([^l])} $str {\\1}]\n\n# Special Tcl Syntax\n# Math ops\nset answer [expr {3 + 2}]\n\n# Comments\nputs $answer ;# Comments in the same line as code must use ;# instead of just #\n\n<\/code><\/pre>\n<h3>Tcl\/Tk Links<\/h3>\n<ul>\n<li><a href=\"http:\/\/www.tcl.tk\/\">Tcl Developer Xchange<\/a><\/li>\n<li><a href=\"http:\/\/wiki.tcl.tk\/\">Tcler&#8217;s Wiki<\/a><\/li>\n<li><a href=\"http:\/\/en.wikipedia.org\/wiki\/Tcl\">Tcl in Wikipedia<\/a><\/li>\n<li><a href=\"http:\/\/www.yosefk.com\/blog\/i-cant-believe-im-praising-tcl.html\">I can\u2019t believe I\u2019m praising Tcl<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Tcl, or Tool Command Language, will not be found in the &#8216;most popular languages&#8217; hall of fame. That is partly because of its &#8216;wierd&#8217; syntax. <a class=\"mh-excerpt-more\" href=\"https:\/\/www.bin-co.com\/blog\/2008\/04\/hello-script-for-tcl\/\" title=\"Hello Script for Tcl\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,28],"tags":[137,162,245,274,281,289],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-scripts","category-tutorial","tag-hello","tag-language","tag-script","tag-tcl","tag-tk","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":0,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}