Would have been nice if you could have named those "little things"
That's a fair point. Here's a modified version of the code doing what I think you might have been trying to do. I'm also realizing I may have misread the question, but I've got momentum now. Might as well paste what I have.
#!/usr/bin/perl
# Use the warnings pragma rather than the -w flag
use warnings;
use strict;
{ package One;
# Define a constructor for One
sub new {
my $class = shift; # Constructors need to know what class they
+'re for
my $self = {};
bless($self, $class); # Tell Perl what $self is being blessed
+into
}
sub test {
my $self = shift; # Is this an object method? Better grab $sel
+f
my $x = pop @_; # I usually shift from the argument list, but
+whatever
# Also, I like to be explicit about what I'm
# popping/shifting from
print "$x\n";
}
}
{
package Two;
use base "One";
# Two::new didn't add anything to One, so I removed it.
sub eg {
my $self = shift; # Is this an object method? Better grab $se
+lf
my $arg = pop @_; # pop() again? Okay, break it out and make
+it explicit.
$self->test($arg); # Is test() an object method? I'll use it a
+s if it was.
}
}
my $obj = new Two();
$obj->eg("hello");
Edit: Incidentally, I think jethro has the solution you're looking for. I've become so used to making everything explicit by spelling out object or module connections that I didn't even think of Exporter.
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, 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, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|