Hi, I'm a newbie in Perl Tk and am trying to write a program that lets a user to choose a directory, like c:\windows. My goal is so that an output file will be written to this directory after the program is finished.

The code (written by someone else) I'm using to access the file's directory is like this:

use Tk; use Tk::FileSelect; use Cwd; $top = new MainWindow; $fs = $top->FileSelect(-verify => [qw/-d/]); print $fs->Show; print "\n";


What I have so far is this:

When I run my program, two windows pop up. The first window (which does other stuff that my program needs) has an entry widget, and the second window is the one where I can select the directory (like the code above).

What I'm having trouble with:

When I select the directory, I want the directory to show up in the entry widget of my first window. i.e. I select "c:\windows" as my directory, so the words "c:\windows" should show up in my entry widget. It's kinda like how getOpenFile automatically returns the string for you.

The problem is that I don't know how to pass this string back to the first widow's entry widget. And will the computer recognize it as an actual directory, and not merely any old string? I just want the computer to eventually write an output file to this directory (i.e. the one that the user chooses). Am I going about this all wrong? Is there a better way?

Thanks for your help!

In reply to Perl Tk & passing directories by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.