Dan Fish wrote: > I've got a Class::Struct array (@stack) that has, as one of it's members, > another array of Class::Struct (@bop) I know how to make assignments > explicitly, but can't figure out the syntax to use to "push" onto the > (stack->bop) array. I need to do this mainly because I'll be pushing > varying numbers of elements onto each (stack->bop) array in arbitrary > sequence (not all nicely contained in a loop like the sample code below...) > > Explicit assignment gets messy as it requires keeping track of the next > index value for each (bop) element in the (stack) array > > The following code is a greatly simplified version of what I'm trying to do, > but I hope it conveys the idea.. > > Thanks, > -Dan > > > =================== code snippet ======================= > #!/usr/local/bin/perl -w > > use strict; > use Class::Struct; > use Data::Dumper; > > my @stack = (); > > struct( foo => { > baz => '$', > bop => '@', > }); > > struct( bar => { > p1 => '$', > p2 => '$', > }); > > #' Tick keeps emacs syntax colorizer happy... > # the above decls seems to "mess it up" > > for (my $i=0; $i < 3; $i++){ > my $f = new foo; > $f->baz($i); > for (my $j=0; $j < 3; $j++){ > my $b = new bar; > $b->p1($i); > $b->p2($j); > > #How would I "push" $b onto "bop" here > #rather than by direct assignment? > > $f->bop($j,$b);
push @{ $f->bop }, $b; > } > push(@stack,$f); > } > > print Dumper([EMAIL PROTECTED]); > > ================== end code snippet ===================== John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>