Re[2]: Objects, threads and so on

2003-09-30 Thread lists_perl_org
Hello all,

(david, sorry if you receive this several times, I've had a hard time
with the email client).

Thank you all for your attention. I'll answer here for the three
who wrote about this thread.

The example David wrote is wonderful. I was missing ": shared".
That was exactly what I wanted to do, but better than what I
wrote :). My skills on Google must be disappearing, 'cause I didn't
find it and really looked for it several times...

> I want to have a class I won't instanciate

Here I was badly trying to define a set of functions, procedures
and attributes which you can use from anywhere in your program,
and which are collected under a common class, but something you
don't have to instanciate => which, in Perl, seems to be a
namespace or package. An example could be a "Config class" which
has methods like WriteConfig or ReadConfig -- like for reading
.ini files, and it has no sense (for me) to instanciate such a
class. My English is not very good and I can't manage to explain
better :( Anyway, I think I have understood what should I do.

About "use strict", I know and I use it in the actual program, but
made a test-case quickly to write the email and I didn't check for
this. I really prefer the way David wrote the global (shared)
variable; I was messing all I have read about perl objects all
around :(

In any case, I will read and study perl-syntax because I see Perl
is a powerful but non-trivial-to-write language... hehe.

Thank you for your help. I'll read this list with attention :)

Con fecha lunes, 29 de septiembre de 2003, 21:49:21, escribió:

d> ... if i understand your question correctly, see if the
d> following
d> helps: ...

--
Best regards,

Fernando Najera


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Objects, threads and so on

2003-09-29 Thread lists_perl_org
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

 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]