> Does Perl have a functional equivalent to Java's StringBuffer object??? I
> have output heading to CGI and to and email (it's a large, ugly script
that
> I'm rewriting for someone and will hopefully cleanup a bit in the process)
> interspersed amongst themselves. I already have a working solution, but
I'm
> still wondering if a stringbuffer.append() type function could exist out
> there somewhere???
>
> What _might_ be a nice option would be to redirect a Print statement to
> output text into some form of buffer (via a filehandle I suppose). I guess
a
> simple temp file could be used for this, but I would like to shy away from
> using files for that purpose.

The obvious solution would be to concatenate things to a string:

 my $StringBuffer = 'initial text';

 # later...

 $StringBuffer .= ' even more text';

But you're probably thinking more along the lines of:

 http://search.cpan.org/doc/GAAS/IO-String-1.01/String.pm

or

 http://search.cpan.org/doc/ERYQ/IO-stringy-1.220/docs/IO/Scalar.pm.html

use IO::Scalar;

    ### Open a handle on a string, and append to it:
    $SH = new IO::Scalar \$somestring
    $SH->print("bar\n");

use IO::Scalar;

    ### Writing to a scalar...
    my $s;
    tie *OUT, 'IO::Scalar', \$s;
    print OUT "line 1\nline 2\n", "line 3\n";

- Ron

_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

Reply via email to