1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/local/bin/perl -w
use Tk;
use strict;
use vars qw( $mw );
use vars qw( $b_array);
use Data::Dumper;
use threads;
use threads::shared;
my @array = ();
threads->new(\&mysub);
$mw = MainWindow->new( -relief => 'flat' );
$mw->geometry('50x50+50+50');
$b_array = $mw->Button( -pady => '1', -relief => 'sunken', -padx => '1', -state => 'normal', -justify => 'center', -text => 'Array', -command => \&button_pressed )->place( -x => 25, -y => 25);
#&UpdateArray("YES"); #=> from here is OK when button_pressed
MainLoop();
sub button_pressed {
print Dumper(\@array);
}
sub UpdateArray {
my $data = $_[0];
my $j = 0;
for (my $i=0; $i<length($_[0]);$i=$i+1){
$array[$i][$j]= $data;
$j++;
}
print Dumper(\@array);
}
sub mysub {
&UpdateArray("NO"); #=> array is empty when button_pressed
}
Quote..... For instance, threads::shared isavailable, but essential does nothing if used on non-threaded Perls (or in non-threaded applications).