L
LeTubs
Hi
What I'm trying do is to have a record structure and then create an array
of those structures and then being able to access those structures via
for loop..... sounds simple, well unfortunately I want do this in perl and
being sort of new to it I'm sort of coming stuck( or continuing to think in
C ). I have written a simple little test program that I'm seeing whats is
going on and trying to figure whats going wrong, and would a appreciate
some expert advice !
Thanks
David
#!/usr/bin/perl
use Class::Struct;
#create a simple record structure
struct Wibble =>{
name => '$',
w => '$',
};
#create a blank array for storage....
@some_array = ();
# create the new member
my $p = Wibble->new();
$p->name("David");
$p->w("w");
# store the new member ( is this correct way to do this ? )
push( @some_array, $p );
# create another member.....
my $p = Wibble->new();
$p->name("William");
$p->w("x");
# store it again
push( @some_array, $p );
#now print out the results....
for( $i = 0; $i < @some_array; $i++ ){
print " $i : $some_array[$i].name, $some_array[$i].w";
}
# Ideal Ouput
1 : Davidw
2 : Williamx
What I'm trying do is to have a record structure and then create an array
of those structures and then being able to access those structures via
for loop..... sounds simple, well unfortunately I want do this in perl and
being sort of new to it I'm sort of coming stuck( or continuing to think in
C ). I have written a simple little test program that I'm seeing whats is
going on and trying to figure whats going wrong, and would a appreciate
some expert advice !
Thanks
David
#!/usr/bin/perl
use Class::Struct;
#create a simple record structure
struct Wibble =>{
name => '$',
w => '$',
};
#create a blank array for storage....
@some_array = ();
# create the new member
my $p = Wibble->new();
$p->name("David");
$p->w("w");
# store the new member ( is this correct way to do this ? )
push( @some_array, $p );
# create another member.....
my $p = Wibble->new();
$p->name("William");
$p->w("x");
# store it again
push( @some_array, $p );
#now print out the results....
for( $i = 0; $i < @some_array; $i++ ){
print " $i : $some_array[$i].name, $some_array[$i].w";
}
# Ideal Ouput
1 : Davidw
2 : Williamx