or what I might be doing terribly wrong?
Processes do not share variables. Once you fork(), each process has its own copy of the variables, and any changes to the variables are local to the process. The subject you need to research is IPC (inter process communication). You might start by reading perlipc.
Here is an example of what you can do:
Note the consequences to the parent, which is not something you want to do in a gui setting. The gui environments I'm familiar with--perl not being one of them--usually have a special setup for executing long running processes, which automatically signal the gui when they are done. You can then set up a listener for that 'event' and do something in response.use strict; use warnings; use 5.010; my @lines = qw{ LINE1 LINE2 LINE3 LINE4 LINE5 }; my $pid = open my $INPUT_FROM_CHILD, '-|'; if (!defined $pid) { die "Couldn't fork: $!"; } if ($pid) { say 'parent: blocking until child sends some data...'; while (<$INPUT_FROM_CHILD>) { #line oriented reading chomp; say "parent: $_"; } waitpid($pid, 0); say "parent: child exited with status = $?"; say 'parent: exiting...'; } else { sleep 2; say $lines[int(rand(@lines))]; close $INPUT_FROM_CHILD; sleep 10; }
In reply to Re: How to pass the value of a variable from a child to parent with gui interface?
by 7stud
in thread How to pass the value of a variable from a child to parent with gui interface?
by ZJ.Mike.2009
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |