For example, doing
open F, "> /some/file" or die;
select(F);
print "Hello there\n";
will print text into /some/file without the handle to be passed to
the print command.
Is there something like this for tcl?
WL
Not built-in, I don't think, but you can create it:
proc select args {
global _selected_channel
if {[llength $args] == 0} {
if {![info exists _selected_channel]} {
set _selected_channel stdout
}
return $_selected_channel
} elseif {[llength $args] == 1} {
set _selected_channel $args
} else {
error "wrong # args: [lindex [info level 0] 0] ?channelId?"
}
}
proc print string {
puts [select] $string
}
--
Glenn Jackman
gle...@ncf.ca
Not built-in, I don't think, but you can create it:
proc select args {
global _selected_channel
if {[llength $args] == 0} {
if {![info exists _selected_channel]} {
set _selected_channel stdout
}
return $_selected_channel
} elseif {[llength $args] == 1} {
set _selected_channel $args
} else {
error "wrong # args: [lindex [info level 0] 0] ?channelId?"
}
}
proc print string {
puts [select] $string
}
set f1 [open /tmp/f1 w]
set f2 [open /tmp/f2 w]
print "line1"
select $f1
print "line2"
select $f2
print "line3"
select stdout
print "line4"
--
Glenn Jackman
gle...@ncf.ca
Not built-in, I don't think, but you can create it:
proc select {{channelId ""}} {
global _selected_channel
if {[string length $channelId] == 0} {
if {![info exists _selected_channel]} {
set _selected_channel stdout
}
} else {
set _selected_channel $channelId
}
return $_selected_channel