http://www.perlmonks.org?node_id=1078967


in reply to Odd scalar behaviour

Which OO framework are you using? Can you show us the object declarations? My best guess is that someone overloaded stringification of the object in question (whatever is getting returned from $$self->{queue}->dequeue()) and some predicate in peekMessage is dodging an uninitialized value.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^2: Odd scalar behaviour
by SimonPratt (Friar) on Mar 20, 2014 at 08:48 UTC

    I'm not using a framework (probably my first mistake :-))

    Sure:

    sub new { my $class = shift; my $self = fields::new($class); my %params = @_; die "ID not defined\n" unless $params{ID}; $$self{id} = $params{ID}; $$self{queue} = Thread::Queue->new(); $$self{handler} = $handler_map{$params{HANDLER}}; $$self{processThread} = threads->new(\&worker, \$self, %params); # Note: No need to explicitly bless the object, as it is already ble +ssed. return $self; }

    The $$self{processThread} = threads->new(\&worker, \$self, %params); line I am really not sure about. I need the worker thread to know which object it is part of (so it knows which Thread::Queue to watch), but it seems a bit clunky to me to effectively be passing in a reference to itself