paul99 has asked for the wisdom of the Perl Monks concerning the following question:

When reading in files in perl i have used in the past something along the lines:

$data = "c:\file.txt"; open DATA, $data or die "failed to open"; while (<DATA>) ( .....some code etc close DATA;
As a beginner to PerlTk, I want to create an entry widget to get the user to enter "c:\file.txt" and assign it to $data variable, so that I can then run my perl routines.
Any help appreciated.

Edited by Chady -- code tags.

Replies are listed 'Best First'.
Re: PerlTk File Input
by Joost (Canon) on Jul 19, 2004 at 15:53 UTC
Re: PerlTk File Input
by mawe (Hermit) on Jul 19, 2004 at 18:47 UTC
    Hi!

    It is better done as Joost mentioned, but if you really want to use an entry-widget, you could do it like this:
    use Tk; my $file; my $top = new MainWindow; my $ent = $top->Entry(-textvariable=>\$file)->pack(); my $but = $top->Button(-text=>"ShowFile",-command=>\&sub_file)->pack() +; MainLoop(); sub sub_file { print $file; # or whatever }
    Hope this helps,

    mawe
      Or even use Tk::PathEntry instead of Entry. This one lets you use the <Tab> key for completion as in modern shells.
      Thx,this works fine.