[tcltk-perl] RE: scalar($w->getOpenFile)
Brought to you by:
hobbs
From: Jeff H. <je...@ac...> - 2004-04-21 16:40:00
|
> 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. > 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. 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). Jeff |