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.


In reply to Re^2: simple script question scope/structure for Perl noob by scotchfx
in thread simple script question scope/structure for Perl noob by scotchfx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.