Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: perl oo

by Caillte (Friar)
on Jan 15, 2001 at 23:47 UTC ( [id://52028]=note: print w/replies, xml ) Need Help??


in reply to perl oo

Hokay... a a few things wrong here... but you were so close that its worth setting things straight.

First, please compile your code with -w and use strict. Using -w would have shown you that perl could not find the Send.pm package. If you use use then perl searches for packages in @INC (the module path) but if you start using a package without using use perl will assume that the package is in the same file as the calling code. Of course, if it isnt then perl will generate an error.

Removing use Send then gives a program that compiles and generates "the: Send,4556" which is almost, but not quite, what you want. The reason for this is that both of the following lines call the same function in the same way:

$obj = Send->new($name); $obj = new Send($name);

Both effectively break down to a call like:

new( Send, $name ); <>Because of this we have to make a couple of changes to your new sub. First you need to read in two variables, the class and thenthe name.

 my($class, $name) = @_;

Your bless line is wrong too, you bless an object into a class, in this case the Send class so, in this case, you would use

bless($self, $class);

This gives the output: "the: lastname, 4556" which is what i think you were looking for.

<teacher_mode>There is still a lot wrong with your prorgam, even with these changes... it still will not compile if you use use strict for a start. But those two changes should set you going in the right direction</teacher_mode>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (None)
    As of 2024-04-25 00:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found