You should always use warnings; and use strict. Otherwise you will experience bugs. Anyways, you can store your default dir in the DATA section of your script, you can also use Inline::Files.
#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::JPEG; use Tk::Dialog; my $def_path; #defaults to current dir in DATA # read last stored value while(<DATA>){ if($_ =~ /^DIR:(.*)$/){ $def_path = $1 } } my $mw = MainWindow->new; # make sure def_dir gets written when program closes $SIG{INT} = sub { &close_it_up }; $mw->protocol('WM_DELETE_WINDOW' => sub { &close_it_up }); my $c = $mw->Canvas( # -tile => $tile, qw/-width 1500 -height 750/)->pack(-side => 'left'); my $path = $c->Label(-text => "Default Path For Saving Input Files", #-font => 'Arial 18 bold' )->place(-relx => 0.23, -rely => 0.4); my $path_text = $c->Entry(-textvariable => \$def_path, -width => 50)->place(-relx => 0.4, -rely => 0.4); my $path_button = $c->Button(-text => "Browse", #-font => 'Arial 8 bold', -width => 5, -command => [\&browse, $def_path])->place(-relx => 0.65, -r +ely => 0.4); MainLoop; sub browse { my $init_dir = shift; $def_path = $mw->chooseDirectory(-title => 'Select directory', -initialdir => $init_di +r, #-mustexist => 1 # scre +ws up on linux ); } sub close_it_up{ open(SELF,"+<$0")||die $!; while(<SELF>){last if /^__DATA__/} truncate(SELF,tell SELF); $def_path ||='.'; print SELF 'DIR:'; print SELF "$def_path"; print SELF $/; truncate(SELF,tell SELF); close SELF; Tk::exit; exit; } ############################################################ __END__ __DATA__ DIR:'.'

I'm not really a human, but I play one on earth CandyGram for Mongo

In reply to Re: chooseDirectory set Default by zentara
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.