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 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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |