![]() |
|
|
|||||||
![]() |
PERL - How to read STDOUT from a Perl function |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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 |
|
|
|
#3 |
|
Posts: n/a
|
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 |
|
|
|
#4 |
|
Posts: n/a
|
> 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 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 |
|
|
|
#5 | |
|
Junior Member
Join Date: Jan 2009
Posts: 1
|
Quote:
Can't you just assign the STDOUT to variable? Something like: $variable = `echo cat123`; print $variable; Best, Joni cr4ft |
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |