Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Answer: How can I write a function's output to a scalar?

by Abigail-II (Bishop)
on Jul 16, 2002 at 14:39 UTC ( #182092=categorized answer: print w/replies, xml ) Need Help??

Q&A > subroutines > How can I write a function's output to a scalar? - Answer contributed by Abigail-II

You can do it with a pipe-open, as described in man perlipc.
#!/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";


Log In?

What's my password?
Create A New User
[Corion]: Hmm - that should be somewhere in the "Release Deployment Plan", but I don't find a good English link (nor a good German one ;) )
[thezip]: My project manager is asking "Why do we need this?" Ahem...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2017-02-23 17:57 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (350 votes). Check out past polls.