0% found this document useful (0 votes)
77 views4 pages

File Read/write

The document contains code snippets demonstrating various Tcl programming concepts including: 1) Reading and writing to files, splitting and replacing strings, regular expressions, expressions, lists, loops, procedures, command line arguments. 2) Key concepts shown include opening and reading/writing to files, splitting strings, regular expressions for search and replace, looping constructs like for, while, foreach, lists with operations like indexing, length, sorting, replacing and appending elements. 3) Examples of procedures, command line arguments, and basic mathematical expressions are also demonstrated.

Uploaded by

srajece
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views4 pages

File Read/write

The document contains code snippets demonstrating various Tcl programming concepts including: 1) Reading and writing to files, splitting and replacing strings, regular expressions, expressions, lists, loops, procedures, command line arguments. 2) Key concepts shown include opening and reading/writing to files, splitting strings, regular expressions for search and replace, looping constructs like for, while, foreach, lists with operations like indexing, length, sorting, replacing and appending elements. 3) Examples of procedures, command line arguments, and basic mathematical expressions are also demonstrated.

Uploaded by

srajece
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

File read/write

set fp [open "a.inp.tcl" r]

set fp_out [open "a.out.tcl" w]

while {[gets $fp data] >=0} {

puts $data

puts $fp_out $data

close $fp

close $fp_out

Change place pin to offset

set i [open "inp2.tcl" r]

while { [gets $i data] >=0} {

set a [split $data "("]

#puts [lindex $a 1]

#puts $a

set b [split [lindex $a 1] " "]

#puts $b

#puts [lindex $b 3]

set d [split [lindex $b 2] "="]

set e [regsub [lindex $d 0] $data [lindex $b 0] ]

set k [regsub [lindex $b 0] $e [lindex $d 0] ]

puts $k

close $i

Add 0.5 in offset

set fp [open "/home/fxece/is13_03.io" r]

set fp_out [open "a.tcl" w]


while {[gets $fp data] >= 0} {

if {[regexp offset $data] >0} {

#set a [split $data " "]

#puts $a

set c [split [lindex $data 2] "="]

#puts $c

set a [expr [lindex $c 1] + 0.25]

#puts $a

set k [regsub [lindex $c 1] $data $a ]

#puts $k

puts $fp_out $k

#puts $a

#puts $data

close $fp

close $fp_out

List

set a {book pen gr paper marks}

puts [lindex $a 2]

puts [llength $a]

puts [lreplace $a 0 4 good]

puts [lset a 0 hi]

puts [lassign $a a b]

puts [lsort $a]

puts [lappend $a bvfc]

Continue

for {set x 0} {$x<10} {incr x} {

if {$x == 5} {
#puts $x

continue

puts $x

#continue

puts "x is $x"

puts "$"

For loop

set b "length tgdggc"

puts [llength $b]

for {set c 0} {$c <= [llength $b]} {incr c} {

puts "@"

foreach a $b {

puts "$a#"

Procedure

proc add {a b} {

return [expr $a+$b]

puts [add 10 30]

puts [add 5 7]

puts [add 56 6]

Whileloop
set x 1

while {$x < 5} {

puts "&"

puts [expr {$x + 5}]

incr x

Command line arguments puts $argv

foreach a $argv {

puts $a

puts [lindex $argv 1]

puts [lindex $argv 0]

You might also like