Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Streaming to Handles

by matija (Priest)
on May 01, 2004 at 09:35 UTC ( #349589=note: print w/ replies, xml ) Need Help??


in reply to Streaming to Handles

You want to write into a file in the module and then read it the calling program and write a bit more and read a bit more? That is NOT going to work. Not with STDOUT, not with pipes, not even with sockets.

It is not the propper way to communicate with the subroutine. Why don't you have the subroutine simply return a bunch of lines together in a string (or an array), and then process them in the calling program as you see fit? That will work much better.


Comment on Re: Streaming to Handles
Re: Re: Streaming to Handles
by crabbdean (Pilgrim) on May 01, 2004 at 09:50 UTC
    I've already created it and got it working passing back an array, which you then can loop through as normal. Problem is in my case the array is going to be returning a MASSIVE amount of data, we are talking of a processing time of about 6 hours. Unless I'm on a supercomputer with a crap load of RAM I'd have to chop that array into pieces and pass it back piecemeal or stream it. Plus streaming is faster I believe. There has to be a way because streaming is possible, I'm just not familiar with the syntax. I've seen modules where people write to a stream and then read the FILEHANDLE on the stream. Help! Please?

    Dean
    The Funkster of Mirth
    Programming these days takes more than a lone avenger with a compiler. - sam
    RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers
      The only way I can think of doing this without heavily restructuring your code is to create a pipe, fork off a child, then have the child write the list of filenames to the pipe and have the parent read them back in.
        ...Which isn't as hard as it sounds. Something like:
        my $f = List->new; my $pid = open(FROM_LIST,"-"); if (!defined($pid)) { die "fork error: $!\n"; } elsif (!$pid) { # Child $f->stream_to(\*STDOUT); $f->look_in('c:/'); $f->list; exit(0); } # Parent while (<FROM_LIST>) { print "$_\n"; }
        should do the trick.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://349589]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-08-30 01:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls