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?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();
In reply to WxPerl and accessing subroutine return variables without direct call of subroutine by Kyshtynbai
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |