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:

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; }
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.

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

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.