Go Back   Velocity Reviews > Newsgroups > PERL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

PERL - How to read STDOUT from a Perl function

 
Thread Tools Search this Thread
Old 07-30-2003, 04:23 PM   #1
Default How to read STDOUT from a Perl function


I would think this is simple to do, but I just can't figure it out this
morning. Assume I have a function in Perl which writes some output to
STDOUT. I want to call this function from a Perl script and capture its
output in a variable.

If this was an executable or even another Perl script, I could use the
open() function. But since this is a Perl function, I can't use open().
Or can I? There's got be be a way, but my brain is just not cooperating
this morning.

Alfred


Alfred von Campe
  Reply With Quote
Old 07-30-2003, 10:45 PM   #2
Jeff Bars
 
Posts: n/a
Default Re: How to read STDOUT from a Perl function
Assuming the function returns a value (and it should):

my $var = function();

or maybe I misread...

-JB

"Alfred von Campe" <> wrote in message
news: om...
> I would think this is simple to do, but I just can't figure it out this
> morning. Assume I have a function in Perl which writes some output to
> STDOUT. I want to call this function from a Perl script and capture its
> output in a variable.
>
> If this was an executable or even another Perl script, I could use the
> open() function. But since this is a Perl function, I can't use open().
> Or can I? There's got be be a way, but my brain is just not cooperating
> this morning.
>
> Alfred



---
Posted via news://freenews.netfront.net
Complaints to


Jeff Bars
  Reply With Quote
Old 07-31-2003, 04:18 PM   #3
Gerard Oberle
 
Posts: n/a
Default Re: How to read STDOUT from a Perl function
Would something like the following work?

open FOO_IN, "perl -e \'require \"file.pl\"; &subroutine_call();\'"|"
or die "blah blah blah";

while (<FOO_IN>) {...}
close FOO_IN;

- Jerry Oberle
perl -e 'printf "mailto%c%s%c%s%cchase%ccom%c", 58, "Gerard", 46,
"Oberle", 64, 46, 10;'


Gerard Oberle
  Reply With Quote
Old 07-31-2003, 09:57 PM   #4
Alfred von Campe
 
Posts: n/a
Default Re: How to read STDOUT from a Perl function
> Would something like the following work?
>
> open FOO_IN, "perl -e \'require \"file.pl\"; &subroutine_call();\'"|"
> or die "blah blah blah";
>
> while (<FOO_IN>) {...}
> close FOO_IN;


Probably (I haven't tested it), but this solution is even uglier than
what I had originally done . It looks like I did not miss something
obvious; this functiononality does not exit in Perl. Basically, what I
want to do is to temporarily assign STDOUT to a Perl variable, so that
everything written to stdout is put in that variable.

Alfred


Alfred von Campe
  Reply With Quote
Old 01-05-2009, 09:00 AM   #5
cr4ft
Junior Member
 
Join Date: Jan 2009
Posts: 1
Default
Quote:
Originally Posted by Alfred von Campe
I would think this is simple to do, but I just can't figure it out this
morning. Assume I have a function in Perl which writes some output to
STDOUT. I want to call this function from a Perl script and capture its
output in a variable.

If this was an executable or even another Perl script, I could use the
open() function. But since this is a Perl function, I can't use open().
Or can I? There's got be be a way, but my brain is just not cooperating
this morning.

Alfred

Can't you just assign the STDOUT to variable?

Something like:
$variable = `echo cat123`;
print $variable;

Best,

Joni


cr4ft
cr4ft is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
VERY basic Perl question geoffh Software 0 08-23-2009 01:00 PM
Help .... How to read a log file using c++... EngSara Software 0 05-17-2008 06:10 PM
VCR to DVD copy: can't read on computer w.edelstein@gmail.com DVD Video 5 03-25-2006 09:11 AM
Re: Unable to read video DVDs and can read Data DVDs Biz DVD Video 0 07-22-2005 04:44 AM
requesting a hand up - read for your Mom [short message with Quotes] Miss Marple DVD Video 1 03-17-2005 10:07 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46