<?xml version="1.0" encoding="windows-1252"?>
<node id="9037" title="String Buffer" created="2000-04-25 17:12:52" updated="2005-08-11 05:21:58">
<type id="1748">
sourcecode</type>
<author id="8990">
kayos</author>
<data>
<field name="doctext">
&lt;code&gt;
# $Id: StringBuffer.pm,v 1.1 2000/04/03 22:53:04 kayos Exp $
package StringBuffer;


sub TIEHANDLE {
    my ($class, $c) = @_;
    return bless(\$c,$class);
}

sub PRINT {
    my ($self) = shift;
    ${$self} .= join('', @_);
}

sub PRINTF {
    my ($self) = shift;
    my ($fmt) = shift;
    ${$self} .= sprintf($fmt, @_);
}       

#   sometimes Perl wants it...
sub DESTROY { };

1;
&lt;/code&gt;</field>
<field name="codedescription">
&lt;p&gt;Sometimes I encounter a script or program that wants to
print directly to STDOUT (like Parse::ePerl), but I want it in a scalar variable.
In those cases, I use this StringBuffer module to make a
filehandle that is tied to a scalar.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;
&lt;code&gt;
use StringBuffer;
my $stdout = tie(*STDOUT,'StringBuffer');

print STDOUT 'this will magically get put in $stdout';

undef($stdout);
untie(*STDOUT);
&lt;/code&gt;</field>
<field name="codecategory">
strings</field>
<field name="codeauthor">
T.R. Fullhart, &lt;a href="mailto:kayos@kayos.org"&gt;kayos@kayos.org&lt;/a&gt;</field>
</data>
</node>
