Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: Classes Are Killing Me

by straywalrus (Friar)
on May 19, 2002 at 04:57 UTC ( [id://167611]=note: print w/replies, xml ) Need Help??


in reply to Re: Classes Are Killing Me
in thread Classes Are Killing Me

I do know what a singleton is, but thanx for that pointer. I got the idea to use the local copy of I had originally just copied the data used in the users junk to the module. but even when i used this constructor:
sub new { my $class = shift; my $self = {}; return bless $self, $class; }
It actually did not work at all. Besides, the second simplest constructor in the perl cookbook was sub new{ bless({},shift);} I saw that in the reference they had shifted off of $self for every function, but as I said earlier I was just copying the code to local vars and only now realize that I can only have one instance of the class if I do that. Yes I realize how to shift of $self, but even when I had all the things that were just descibed, I still could not call the functions like this:$foo->name("straywalrus");. Instead I had to call every function with the class name preceding the function name with the C++ scope operators betwixt the two ( I have no idea what the scope "::" operator is called in Perl). Every call was made like it was shown in the test program. Surely there is a way to correct this, even though I shift off $self and do as was above described. Thanx straywalrus

Replies are listed 'Best First'.
Re: Re: Re: Classes Are Killing Me
by chromatic (Archbishop) on May 19, 2002 at 05:17 UTC

    The simplest remaining possibility is that $foo is not a person, that your constructor is somehow failing. This could be due to the package not loading. If I were you, I'd enable strictures and warnings and add this line after attempting to create the object:

    print "Foo is a ", ref($foo), "!\n";

    You shouldn't have to preface method calls with package names, nor do you need to import anything from Person (so you can safely drop the method name list). Oh, and the double colons are package name separators.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://167611]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (8)
As of 2024-04-19 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found