deewanagan has asked for the wisdom of the Perl Monks concerning the following question:

Hello! can any one tell how to write/read data to/from the buffer without sending it over the network? just like storing data in the buffer and read/write it whenever we want. Thanx

Replies are listed 'Best First'.
Re: How to write to Buffer
by Corion (Patriarch) on Nov 22, 2008 at 08:45 UTC

    If you meant how to treat a scalar like a file, then you want to use open with a reference to the scalar:

    my $data = 'Hello World'; open my $fh, '>', \$data or die "Couldn't open \$data as a file"; seek $fh, 6; print <$fh>

    But then again, your question is a bit vague, so I don't know if that's what you're looking for.

Re: How to write to Buffer
by ikegami (Patriarch) on Nov 22, 2008 at 08:06 UTC
    That's automatic unless you turned on autoflush.
    use IO::Handle qw( ); $fh->autoflush(1); # Don't buffer. print $fh "foo"; $fh->autoflush(0); # Use buffer. print $fh "foo"; # Only sent when buffer is full or flushed. $fh->flush(); # Send what's in buffer (if anything) now.