Hi guys! I'd like to do the following: I have a very simple GUI form, which has menu File. In that menu user can choose Source directory and Out directory. Than, if he presses Process button from Action menu, this to dirs should be processed (doesn't matter how exactly in this case). Please see the code:
use strict; use Wx; package WxPerlComExample; use base qw(Wx::App); sub OnInit { my $self = shift; my $frame = WxPerlComExampleFrame->new(undef, -1, "WxPerl Example" +); $frame->Show(1); $self->SetTopWindow($frame); return 1; } package WxPerlComExampleFrame; use base qw(Wx::Frame); use Wx qw( wxDefaultPosition wxDefaultSize wxDefaultPosition wxDefaultSize wx +ID_EXIT ); use Wx::Event qw(EVT_MENU); our @id = (0 .. 100); # IDs array sub new { my $class = shift; my $self = $class->SUPER::new( @_ ); ### CODE GOES HERE ### # Create menus my $firstmenu = Wx::Menu->new(); $firstmenu->Append($id[0], "Choose Source dir"); $firstmenu->AppendSeparator(); $firstmenu->Append($id[7], "Choose Out dir"); my $secmenu = Wx::Menu->new(); $secmenu->Append($id[8], "Process files"); $secmenu->Append(wxID_EXIT, "Exit\tCtrl+X"); # Create menu bar my $menubar = Wx::MenuBar->new(); $menubar->Append($firstmenu, "File"); $menubar->Append($secmenu, "Actions"); # Attach menubar to the window $self->SetMenuBar($menubar); $self->SetAutoLayout(1); # Handle events EVT_MENU( $self, $id[0], \&ChooseIn ); EVT_MENU( $self, $id[7], \&ChooseOut ); EVT_MENU( $self, $id[8], \&ProcessFiles ); EVT_MENU( $self, wxID_EXIT, sub {$_[0]->Close(1)} ); return $self; } ### PUT SUBROUTINES HERE ### sub ChooseIn { my ($self, $event) = @_; my $dialog = Wx::DirDialog->new($self, '', '', &Wx::wxDD_CHANGE_DI +R ); $dialog->ShowModal; my $dir_in = $dialog->GetPath; # That's what I want to have access + to } sub ChooseOut { my ($self, $event) = @_; my $dialog = Wx::DirDialog->new($self, '', '', &Wx::wxDD_CHANGE_DI +R ); $dialog->ShowModal; my $dir_out = $dialog->GetPath; # That's what I want to have acces +s to } # sub ProcessFiles { # ***SOME PROCESSING CODE*** # } package main; my($app) = WxPerlComExample->new(); $app->MainLoop();
The question is - how do I get variables $dir_out and $dir_in from subs ChooseIn and ChooseOut? I have to pass this vars to ProcessFiles sub, while this subs are not called directly, only via reference. I actually can make them anonymous subs as the third argument of EVT_MENU, and define this vars before, but is it the best solution?

In reply to WxPerl and accessing subroutine return variables without direct call of subroutine by Kyshtynbai

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.