in reply to Re: simple script question scope/structure for Perl noob
in thread simple script question scope/structure for Perl noob

you guys... Rock!

Thanks for all the re's in so short a time - I was thinking I'd be lucky to get one or two by the end of the day:)

I've added "use strict;" and "use warnings;" and have declared all my global vars "our", all local block vars "my" etc..

Grandfather is correct with his sample of my input - here is an extended snippit for further clarity:

1-1 1-2 1-3 1-4 1-2->2-1 1-4->3-4 2-1 2-2 2-3 2-4 2-2->1-3 2-4->3-3 3-1 3-2 3-3 3-4 3-2->2-3

the /\d-\d/ lines are individual events to be unshift'd to (and later pop'd from) the @p_s 2D-array, and /\d-\d->\d-\d/ are dependencies to be added to the %sender and %receiver hashes...

Currently Eclipse is throwing the following error:

Use of uninitialized value in array element at C:/Lamport.pl line 69.

The error refers specifically to the following lines:

foreach $pid (@p_s) { #...rest of scheduler loop }

I ran this loop alone with only a print "$pid\n"; statement and got a set of ARRAY(0x186b8f8) values for $pid. I think that I've been to liberal in my use of foreach() and will restructure this more intelligently.

I'm curious why the loop seems to execute for Grandfather though...? Perhaps it is because his test case was limited to a single process/stack....

Any suggestions on an good way to iterate through the first level (@p_s[]) of a 2D array? The trick is that I need to get an index for all of the @p_s[$pid][#pop'd] stacks one at a time, (each $pid stack is pop'd once one level at a time then the process is repeated)? I think I can do this with a regular while loop provided that I count the number of processes while parsing the input, however is there a more elegant way of doing this?

Many Thanks, Thanks and Thanks again to all of you for the quick responses & insight - ya'll have helped me immensely already.