SPUG: Attaching a string to STDOUT

Brian Hatch bri at ifokr.org
Mon Apr 19 23:13:11 CDT 2004



> I'd like to override STDOUT so that 'print' and friends append to a
> string, rather than writing to a physical file.  How may I do this?  Any
> help is appreciated.
> 
> (Background: I have a large and complex gawk script (a Cobol data type
> translator -- not my code, thank goodness).  I need to integrate its
> functionality into my Perl environment, preferably without having to
> understand the gawk code in depth.  I've run it through a2p, and now I'm
> trying to encapsulate the resulting Perl into a module.  Simpler
> solutions are rendered impractical by our weird platform.)  


	
Hmmn - wonder if you can override the print function.

Or perhaps fork with something similar to

	if ( open STDOUT, "-|"  ) {
		do lots of printing
	} else {
		while (<STDOUT> ) {
			$a .= $_
		}
		do something with $a
	}

Or perhaps a pipe inside the program itself (though you'll
need to clean out print periodically, lest it fill up and
you block indefinitely.)



-- 
Brian Hatch                  Scientists have finally
   Systems and                isolated the gene that
   Security Engineer          makes scientists want
http://www.ifokr.org/bri/     to isolate genes.

Every message PGP signed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.pm.org/pipermail/spug-list/attachments/20040419/9d0e15c4/attachment.bin


More information about the spug-list mailing list