#!/usr/bin/perl use strict; use warnings 'all'; sub my_function { # Does a lot, then writes print "Foobar!"; } my $pid = open my $kid => "-|"; die "Failed to fork: $!\n" unless defined $pid; unless ($pid) { my_function; exit; } my $result; { local $/; $result = <$kid>; close $kid or die "Failed to close pipe: $!\n"; } print "Got: $result\n";
Abigail
In reply to Re: How can I write a function's output to a scalar?
by Abigail-II
in thread How can I write a function's output to a scalar?
by echosilex
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |