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>


In reply to Re: perl oo by Caillte
in thread perl oo by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.