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;
> }
>
> sub AddTrain
> {
>         my $self = shift;
>         my $trainName = $_[0];

How are you calling this function.  the formulation above looks like the call should 
be:
AddTrain($schedule_day_object, $train_name);

If that is the case, then your parameter catch would be neater and more understandable 
as:
my ($self, $trainName) = @_;

or:
      my $self = shift;
      my $trainName = shift;


>         # $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.
> Useless use of a constant in void context at scheduleday.pm line 24.
> scheduleday.pm syntax OK

Check the package statement in Train.pm, and try compiling it separately before using 
it in this file.

> 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?
>
> Also, I am getting strange behavior when running this through Internet
> Explorer.  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.

$trainName ain't there.  You've already commented out to lines dependent on this 
variable.  Presumably this was because they raised errors.  Check how you are getting 
a value into $trainName.  Something is going wrong there.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to