[tcltk-perl] Re: scalar($w->getOpenFile)
Brought to you by:
hobbs
From: Gisle A. <gi...@Ac...> - 2004-04-21 18:04:26
|
"Jeff Hobbs" <je...@Ac...> writes: > > Gisle Aas <gi...@Ac...> writes: > > > > > To me it wrong if: > > > $tcl->Eval("set var {a b c}"); > > > returns something different to perl than > > > $tcl->Eval("set var [list a b c]"); > > > if these two expressions have exactly the same semantics in Tcl. > > > > > > I would suggest that we always return the string in scalar context and > > > always list in list context. If the value is not a valid list, then > > > we croak in list context. > > The thing is that there is a difference, it's just very, very > subtle. The problem is that the subtle distinctions are very > important. So tell me what breaks if we do it like this. > > If you try the following program: > > > > #!/usr/bin/perl -w > > > > use Tcl::Tk qw(:perlTk); > > > > my $mw = MainWindow->new; > > my $label = $mw->Label(-text => "Hello")->pack; > > if (my $file = $mw->getOpenFile) { > > $label->configure(-text => "File [$file]"); > > $mw->after(5000, sub { $mw->destroy }); > > } > > > > MainLoop; > > > > and then hit "Cancel" to the dialog that pops up, then we > > fill in the field with something like "File > > [ARRAY(0x8141ad8)]". Apparently tk_getOpenFile returns a > > list instead of string, but this is not documented. Since > > This is just a bad example. The fact that it returns anything > on unix is wrong wrong wrong (and possibly a bug to look into). > On Windows, the expected "" is returned and thus you never > enter into that loop. > > Looking into the Tk code ... I'm suspecting bug, as I see that > the variable returned is specifically set to "" (empty string, > not empty list) when cancel is hit. So why was it returning a reference to an empty array then? Some bug in the Tcl.pm interface code? > The important thing in getOpenFile is in making sure whatever > changes you do correctly handle files with spaces and multiple > files (in case you pass -multiple 1 to the dialog). If you call $mw->getOpenFile in list context it should all work. And if you provide -multiple 1 you probably know that you must do that. --Gisle |