Rob Richardson wrote:
> Greetings!
>
> I have the following class in a .pm file:
>
> use warnings;
> use strict;
> package ScheduleDay;
>
> use Train;
>
> sub new
> {
> my $self = {}; # $self is a reference to an anonymous, empty (for
> now) hash
> bless $self;
> return $self;
> }
n.b. this constructor is not inheritable if you ever derive a subclass from
ScheduleDay. You might want to consider using:
sub new {
my $class = shift;
$class = ref $class || $class;
bless {}, $class;
}
>
> sub AddTrain
> {
> my $self = shift;
> my $trainName = $_[0];
> # $self->{$trainName} = new Train;
> # $self->{$trainName}->Load(@_);
> print " Added train named ", $trainName, "<br>"; }
>
> "Where no one has gone before!";
>
>
> When I run perl -c on this, I get the following messages:
> Subroutine new redefined at Train.pm line 106.
This is likely a problem in Train.pm, which you didn't share with us. Do you
get the same message from perl -c Train.pm?
> Useless use of a constant in void context at scheduleday.pm line 24.
A warning for the phrase. If you don't like the warning, replace the phrase
with the more idiomatic literal 1;
> scheduleday.pm syntax OK
So scheduleday.pm compiles OK. But it should be named ScheduleDay.pm.
>
> What is going on here? Why can't I have a class that uses another
> class and have both classes have a "new" method? What do I have to
> do to get this scoped correctly?
You can have this. Your problems lie elsewhere.
>
> Also, I am getting strange behavior when running this through Internet
> Explorer.
Running what through Internet Explorer? Assuming code not in evidence :~)
> If the print statement in AddTrain() is modified to avoid
> the use of $trainName, the program runs as expected and IE displays a
> page with one line of print for every train I try to add. However, if
> I try to print the name of the train as contained in $printName (and
> as shown above), the result age is never displayed and IE just waits
> and waits and waits for something that never happens.
???
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]