Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
When I run my project:#!/usr/local/bin/perl use strict; use warnings; package Test1; sub new { my $class = shift; my $self = { _txt => shift }; bless $self, $class; return $self; } sub _sub1() { #private method my $self = shift; $self->{_txt} = "bar"; return $self->{_txt}; } sub sub2() { #public method _sub1(); } sub getTxt() { my ($self) = @_; return $self->{_txt}; } 1;
I get "foo" and I want to get "bar". What am I doing wrong?my $object = new Test1( "foo"); $object->sub2(); print $object->getTxt();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: OOP method usage
by kcott (Archbishop) on Jul 07, 2012 at 09:29 UTC | |
by Anonymous Monk on Jul 07, 2012 at 09:37 UTC | |
|
Re: OOP method usage
by Anonymous Monk on Jul 07, 2012 at 09:19 UTC | |
by Anonymous Monk on Jul 07, 2012 at 09:32 UTC | |
by Athanasius (Archbishop) on Jul 07, 2012 at 09:56 UTC | |
|
Re: OOP method usage
by tobyink (Canon) on Jul 07, 2012 at 11:50 UTC | |
|
Re: OOP method usage
by Don Coyote (Hermit) on Jul 07, 2012 at 10:31 UTC | |
|
Re: OOP method usage
by Anonymous Monk on Jul 07, 2012 at 12:34 UTC | |
by tobyink (Canon) on Jul 07, 2012 at 19:00 UTC | |
by Anonymous Monk on Jul 08, 2012 at 20:44 UTC |