Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to modify a struct within a list.

Status
Not open for further replies.

titanandrews

Programmer
Feb 27, 2003
130
US
Hello,
I see tons of posts about Class::Struct module but unfortunately none of them help me. I have a series of different instances of structs which are stored in a list. I want to be able to modify an element of a list that is in the struct that is stored in the list. Follow that? I am certain my syntax is the problem, but I just can't figure it out. Here is a simple example of what I am trying to do:
Code:
use Class::Struct;

struct defs =>
{
   name  => '$',
   types => '@',
};

my @alldefs;
my $defs = defs->new( name  => 'Fred',
                      types => ('this','that');

push(@alldefs,$defs);
my $otherdefs = defs->new( name  => 'Bilbo',
                           types => ('loot','boot');

push(@alldefs,$otherdefs);

# --- Modify the name of element 0. THIS DOES WORK!
$alldefs[0]->name = 'Barry';

# --- BUT HOW DO I GET TO AN ELEMENT OF THE LIST?? 
$alldefs[0]->types(0) = 'toot';


I get: "Can't modify non-lvalue subroutine call" compiler error.

I have also tried other methods of changing this value but have failed. Does anyone know?

many thanks,

Barry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top