A
AJ
I want to have an array in a class I am making. I was testing out the
constructor by passing values to it, let it do its thing. Then call a
function that prints each class member out. Everything goes smooth
until I get to printing the array. It only prints the first member of
the array. I don't even think the constructor is setting the array
correctly the first time. I am new to perl, can someone help me.
Here is my class file:
package Router;
sub new {
my $Router = shift;
my ($name, $hCoord, $vCoord, $weight, @bob) = @_;
my $ref = {Name => $name, hCoord => $hCoord, vCoord => $vCoord,
weight => $weight, @{links} => @bob};
bless ($ref, $Router);
return $ref;
};
sub printShit{
my $ref = shift;
print "name: $ref->{'Name'}\n";
print "weight: $ref->{'weight'}\n";
print "hCoord: $ref->{'hCoord'}\n";
print "vCoord: $ref->{'vCoord'}\n";
print "LinkList: $ref->{'links'}\n";
}
1;
Here is my testFile that has a main:
use Router;
@names = ("hello", "1", "man");
$bob = new Router("wow", 1, 2, 3, @names);
$bob->printShit();
constructor by passing values to it, let it do its thing. Then call a
function that prints each class member out. Everything goes smooth
until I get to printing the array. It only prints the first member of
the array. I don't even think the constructor is setting the array
correctly the first time. I am new to perl, can someone help me.
Here is my class file:
package Router;
sub new {
my $Router = shift;
my ($name, $hCoord, $vCoord, $weight, @bob) = @_;
my $ref = {Name => $name, hCoord => $hCoord, vCoord => $vCoord,
weight => $weight, @{links} => @bob};
bless ($ref, $Router);
return $ref;
};
sub printShit{
my $ref = shift;
print "name: $ref->{'Name'}\n";
print "weight: $ref->{'weight'}\n";
print "hCoord: $ref->{'hCoord'}\n";
print "vCoord: $ref->{'vCoord'}\n";
print "LinkList: $ref->{'links'}\n";
}
1;
Here is my testFile that has a main:
use Router;
@names = ("hello", "1", "man");
$bob = new Router("wow", 1, 2, 3, @names);
$bob->printShit();