Abdullah Al Noman
Abdullah Al Noman

Reputation: 2878

How to read and write from a file in tcl mql?

I want to read from a text file containing names and I want to check if the names contain the letter a . if so then I want the output to be y else n in out.txt file

inputs 

noman 
Lily 

####################

outputs 

y
n 

Upvotes: 0

Views: 789

Answers (2)

JigarGandhi
JigarGandhi

Reputation: 243

> set fp [open "input.txt" "r+"] ; set out [open "output.txt" "w"]
>          #loop through warehouse item rel and disconnect
>          while { [gets $fp line] >= 0 } {
>     puts $out $line ; }
> 
> close $fp close $out;

you need to add the conditional line in the above code:

while { [gets $fp line] >= 0 } {
    if {[regexp {a} $line]} {
       puts $out "y"
    } else {
       puts $out "n"
    }
}

Upvotes: 2

Abdullah Al Noman
Abdullah Al Noman

Reputation: 2878

set fp [open "input.txt" "r+"]
set out [open "output.txt" "w"]
         #loop through warehouse item rel and disconnect
         while { [gets $fp line] >= 0 } {
    puts $out $line ;
}

close $fp
close $out;

This works

Upvotes: 0

Related Questions