| Category: | strings |
| Author/Contact Info | T.R. Fullhart, kayos@kayos.org |
| Description: | 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. Example:
|
# $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;
|
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: String Buffer
by bruno (Friar) on Aug 24, 2008 at 13:58 UTC | |
by FunkyMonk (Bishop) on Aug 24, 2008 at 15:10 UTC | |
by ambrus (Abbot) on Aug 25, 2008 at 13:07 UTC |