Rob Richardson wrote:

I am seriously confoogled about how to get my array back from a
reference. This is the train scheduling program you've been hearing a
lot about from me. The array holds the names of the crew members on
the train. The train object is created with the following routine:

sub new
my $class = shift;
my $self = {};
$self->{'crew'} = [];
bless $self, $class;
return $self;

Each job on a train has a position in an array. Engineer might be
position 0, conductor 1, brakeman 2, and so on. Crew members are
recorded by the following routine:
Interesting, personally I would make each member have a slot in a hash,
but if an array works best for your app then whatever works...
sub AddCrewMemberByIndex
my $self = shift;
my $volunteer = shift;
my $index = shift;

if (!defined($self->{'crew'}[$index]))
I am not sure of the above syntax, I know there are shortened syntaxes
like that where Perl just does the right thing, but I like being
explicit, are you sure anything is getting assigned to the array (I am
assuming there would be a syntax error if it wasn't).

if (!defined($self->{'crew'}->[$index])) {
$self->{'crew'}[$index] = $volunteer;
my @crewMembers = $self->{'crew'};
Right here you are setting the first index of @crewMembers to the array
reference rather than the elements of the array. You need to
dereference it like you do below, with:

my @crewMembers = @{$self->{'crew'}};

If you are just trying to get a count, you might do this all at once
rather than the below line, with:


And you may want to explicitly set the return value if that is what you
are doing by using 'return'.
my $crewCount = @crewMembers;

Once a crew member signs up, a comma-separated value file is generated
that has all of the information about the train. Here's a sample:

2.14.2003,Wine Train BX,17:00,Allan,,Crim,,Sharon Fain,,,,,A Miller,,,,
2.15.2003,Scenic,8:00,Green,Jon Knight,Larry Blanchard,,Cliff
Stadler,,I Pallaise,,,Karen Stadler,Ron Barb Lewis,D Conrad,Joe
Dorsey,Pete Pilkey
2.19.2003,School Train,9:00,,,,,,,,,,Pete Pilkey,F Williamson,,,

(Note: Each date in this sample has its own line. There are no line
breaks within trains.

These lines are generated by the following routine:

sub FileString
my $self = shift;
my $result;
my @data = ($self->GetDate(),
$result = join(',', @data);
return $result;

If the GetCrewList() is removed, everything works. If GetCrewList() is
included, the program stops. It's a web page generation program, and
Internet Explorer just waits and waits and waits for something to
display, and never gets it. Here's GetCrewList():

sub GetCrewList
my $self = shift;
return $self->{'crew'};

There aren't any syntax errors in any of this, or at least none are
reported by perl -c. Does anyone have any idea why my program may be
I don't see what could be wrong with your method, try calling
GetCrewList explicitly on the object and printing the resulting array by
itself outside of the context of the FileString method. This might give
you a place to start. You might make sure the others are successful too
by calling them directly as well. Then you can try the more complex method.



Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
postedJul 20, '03 at 3:36p
activeJul 20, '03 at 3:36p

1 user in discussion

Wiggins d'Anconia: 1 post



site design / logo © 2021 Grokbase