I always get majorly confused when I have to deal with Arrays of Arrays, Arrays of Hashes etc. The Camel book has a good section on this, but it is not always enough. That's why each time I do one, I document it in a file on my disk. However, I have not done this one before. I am extracting Bill of Material (BOM) data from our Oracle system. In my case, each BOM has any number of line items (array) and each line has 5 data items that I am working with (array of arrays). However, any line item can be a "part" that is itself another BOM, so I end up with a sort of tree structure. As I enumerate each line on the TOP LEVEL BOM, when I come to another BOM, I have to stop what I'm doing, "save my place" (yet another array of arrays), and go down into this next BOM. To save my place, I have an array named "stack" upon which I push the entire BOM currently being enumerated, along with several scalars that have to do with what line item I stopped at and so on. The code below demonstrates exactly what I'm doing. The code works, so I'm OK there, but I can't get over the feeling that there is a better way to implement my stack. If anybody has any advice, I'm all ears. ============================= use strict; use warnings; my $i = 2; my $curlvl = 0; my @stack = (); my @thisBOM = ( ["10", "1", "1", "MS51957-59-10", "Screw, Pan HD, 2-56 x .5"], ["20", "2", "1", "MS51957-59-20", "Screw, Pan HD, 4-40 x 1"], ["30", "3", "1", "MS51957-59-30", "Screw, Pan HD, 6-32 x 1.25"] ); # Just print the BOM for reference. print "i.....: $i\n"; print "curlvl: $curlvl\n"; for my $i (0..$#thisBOM) { print "$i: @{$thisBOM[$i]}\n"; } print "\n\n\n"; # Save our place. push @stack, [($i, $curlvl, [@thisBOM])]; # re-init the variables. $i = $curlvl = ''; @thisBOM = (); # Now, recover where we left off. ($i, $curlvl, @thisBOM) = @{pop @stack}; @thisBOM = @{$thisBOM[0]}; # Print the BOM again to make sure it came off the stack the way it went on. print "i.....: $i\n"; print "curlvl: $curlvl\n"; for my $i (0..$#thisBOM) { print "$i: @{$thisBOM[$i]}\n"; } print "\n\n\n";
_______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs