Fernando wrote: > > I'm quite new to Perl so please bear with me :) We have no choice: this is, after all, perl.beginners!
> I've experience in Delphi so I thought I knew about objects... it > seems I don't :( Yes you do :) But you're confusing methodologies with implementations. > 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 > within threads/forks. Threads and forks are something layered on top of Perl, and therefore implicitly non-standard, beyond an explicit Perl version. > use FOO; Which will try to compile FOO.pm and to execute FOO::import. > FOO->make(); > FOO->make(); The constructor for a Perl object is, traditionally, 'new'. But this is not bound by the language and can have any name that you want. However this looks like two instantiations, which you said you weren't doing, and both of which are discarded (in either Delphi or Perl) so I don't see what you're trying to do here. > 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); } } Again I am disconcerted, as you have an object instantion in each of two threads, which is immediately discarded. > while (1) {} > > -- FILE FOO.pm > > package FOO; > > %FOO::e = {}; This wouldn't compile if you wore the helmet of Perl salvation, being: use strict; # always use warnings; # usually You're trying to set a hash (being a list of paired values) to a single value (which is an empty hash reference). > sub make { > my $self = shift; > %FOO::e->{'something'} = %FOO:e->{'something'} + 1; > print %FOO::e->{'something'}."\n"; > } This declares 'FOO::make' because of your 'package' statement above. Call it 'FOO::new' to make others in the Perl world feel at home. Any constructor parameters are values to help form the object. Your constructor cannot have a $self parameter as, if it is useful at all, it is to copy values from an existing object of the same type or of a subclass. It will usually be called 'clone'. Back to your top line: > So I can access them and change them from within threads/forks Within a single thread, you could declare or require another module containing package MODULE; our $var1; our $var2; etc. Which will be accessible externally as $MODULE::var1, $MODULE::var2. You could also 'use' that code as an external module which will let you access synonyms to those values in the current package as $var1, $var2 etc. Unless you have a comprehensive requirement IMO this is not worth considering. Say more about your application and we will help further. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]