in reply to Re^2: Noob OO Question
in thread Noob OO Question

Here's a sub-question regarding this. So, I tried dereferencing it by running this.
my $testing = $self->{test_b}; print $$testing->();
This works!! But how come I cannot do this?
print $$self->{test_b}->();
It gives us this output.
Not a SCALAR reference at Hi.pm
Also, how do I dereference '$test->method_d()'?

Replies are listed 'Best First'.
Re^4: Noob OO Question
by JavaFan (Canon) on Jun 08, 2010 at 00:01 UTC
    $$self->{test_b}->() first dereferences $self. Writing $self->{test_b}->() should work. Or without arrows: &{$$self{test_b}}(). Note the placement of the outer parens.
    Also, how do I dereference '$test->method_d()'?
    You don't. $test->method_d() returns a string.
      Typing it like this doesn't work for me.
      $self->{test_b}->()
      It gives me this output.
      Not a CODE reference at Hi.pm
        Better yet, change
        my $test = new Hi( test_a => 'hello', test_b => \sub{ return 1 }, test_c => \sub{ get_me( $get_a, $get_b ) }, );
        to
        my $test = new Hi( test_a => 'hello', test_b => sub{ return 1 }, test_c => sub{ get_me( $get_a, $get_b ) }, );

        There's no reason for the extra level of indirect.