[Chicago-talk] trouble caputuring return value
Shlomi Fish
shlomif at iglu.org.il
Wed Mar 31 06:13:27 PDT 2010
Hi Richard!
On Wednesday 31 Mar 2010 15:37:16 Richard Reina wrote:
> I have a program that opens a separate terminal and prompts the user for
> some information. However, for some reason I can't seem to capture the
> return value. Does anyone happen to know why the value returned by
> get_info.pl is not getting returned? Any help would really be appreciated.
>
> Thanks
> Richard
>
> #!/usr/bin/perl -w
>
> use strict;
> my $info;
>
> system(q{gnome-terminal --geometry=80x12-0-30 -x perl -e 'require
> "./get_info.pl"; ($info) = get_input();'});
You should not expect Perl to assign to a variable in the main program by
evaluating an assignment to its name in a different process. To communicate
with a child process you need inter-process communications, such as anonymous
pipes, sockets, named pipes, System V IPC, mmap, using the file-system for
that, etc. Please read a little about UNIX multi-processing basics (a lot of
which is also relevant to Windows and other operating systems).
> print $info . "\n";
>
>
> <<<<<<< get_info.pl >>>>>>>>
> #!/usr/bin/perl -w
>
> use strict;
>
> print "Enter Info\n";
> chomp (my $info = <STDIN>);
>
> return $info;
You cannot use return to return an arbitrary Perl value from a program. It
only works for functions. As far as C and UNIX are concerned, everything that
comes out of a process must be in sequences of octets. You need to use
"print()" on something to emit it to the outside somehow.
Regards,
Shlomi Fish
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
What does "Zionism" mean? - http://shlom.in/def-zionism
Deletionists delete Wikipedia articles that they consider lame.
Chuck Norris deletes deletionists whom he considers lame.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
More information about the Chicago-talk
mailing list