Hi all,
I'm quite new to Perl so please bear with me :)
I've experience in Delphi so I thought I knew about objects... it seems I don't :(
I want to have a class I won't instanciate (static members and
variables), with global vars so I can access them and change them from
withing threads/forks.
-- FILE test.pl
use FOO;
FOO->make(); FOO->make();
use Thread;
my $t = new Thread \&th1; my $u = new Thread \&th2;
sub th1() { while (1) { FOO->make(); sleep(1); } } sub th2() { while (1) { print "\t"; FOO->make(); sleep(2); } }
while (1) {}
-- FILE FOO.pm
package FOO;
%FOO::e = {};
sub make { my $self = shift; %FOO::e->{'something'} = %FOO:e->{'something'} + 1; print %FOO::e->{'something'}."\n"; }
-- RESULTS --
1 2 3 3 4 5 4 6 7 5 8 ...
Obviously it doesn't work.
I have tried a lot more of things and I don't know how to make it work. The same applies if I use fork() instead threads.
Is there any way to make this work?
Thank you very much in advance!
Fernando Najera
Maybe you would do better to learn perl-syntax well before you jump into your actual application. A common problem for people conversant with many languages is that they always try translate their work in all languages though their command on all languages is not the same
A hash array reference is always written with $sign not % so change %FOO::e = {}; ==> $FOO::e
in all places
I havent gone thru the entire code , But I think you can take it further
Ram
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]