OK. I was really proud about my "no question" streak. Me and Camel 3 have been snuggling well lately but.... I run this and get:
Use of uninitialized value in foreach loop entry at ./tryMoreKids line + 33, <> line 2. Use of uninitialized value in foreach loop entry at ./tryMoreKids line + 33, <> line 2. Use of uninitialized value in string ge at ./tryMoreKids line 43, <> l +ine 2.
All refer to a var declared with our outside the scope of the loop where the action is and are not myed or localed in any way. AFAICT, it should be fine. The whole point of this code is to figure out how to control the number of children one parent has dynamically - so if you've got a better way to do that by all means let me know. Otherwise, here's my attempt (a prototype) thus far:
use strict; use warnings; our $children; our $new_kids; FORK: { if ( !$children ) { print 'How many children to start with? [5]: '; $children = <>; chomp $children; unless ($children) { $children = '5'; } die "only numbers for kids, please\n\n" if $children =~ /\D/; for ( 1..$children ) { my $child; my $signal = $_; die "Can't fork: $!" unless defined ($child = fork()); if ($child == 0) { # i'm the child! &dummy(); } else { # i'm the parent while ( $signal ge $children ) { &interact(); redo FORK; } } } } else { for ( 0..$new_kids ) { my $child; my $signal = $_; die "Can't fork: $!" unless defined ($child = fork()); if ($child == 0) { # i'm the child! &dummy(); } else { # i'm the parent while ( $signal ge $new_kids ) { &interact(); redo FORK; } } } } } sub dummy() { sleep 90; exit; } sub interact() { print 'Current number of children is: ', "$children", '. i.e. thes +e:', "\n\n"; system('ps -ef | grep tryMore | grep -v grep'); print "\n\n"; print 'Minus one for the parent, of course', "\n\n"; print 'How many children do you want to add? [1]: '; my $new_kids = <>; chomp $new_kids; $new_kids = '0' unless $new_kids; unless($new_kids) { $children += 1; } else { $children += $new_kid +s; } return; }
"A man's maturity -- consists in having found again the seriousness one had as a child, at play." --Nietzsche

In reply to our + redo = ??? by jptxs

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.