If you want the user to have a directory set by default the next time he runs your program, then you'll have to 'save state'. Try using a config file, where you write the directory the user chose, and have your program reading that file at the begining and look for that info. The first time the program is executed that information will not be there, but there will be something the next time.

update: below is some code you can adapt to include in your program. Error checking on dealing with the file is not in the script, as I don't know TK (and how to, visually, alert the user in case of errors) and I would have the script dieing. Run the script and look at config.txt's contents, and then modify the value of the variable $new_default, run it again and look for differences.

use strict; use warnings; my $file = "config.txt"; my $default_dir = ""; my @config; my $content; if (-f $file) { open CONF, "<$file"; $content = <CONF>; close CONF; if ($content =~ /DEFAULT_DIR/) { @config = split /:/,$content; $default_dir = $config[1]; } } my $new_default = "default_path"; if($new_default ne $default_dir) { open CONF, ">$file"; print CONF "DEFAULT_DIR:".$new_default; close CONF; }

After all this, do go and take a look at open. It is important that you know how to deal with files.


In reply to Re: chooseDirectory set Default by olus
in thread chooseDirectory set Default by lil_v

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.