IO_Scalar_synopsis [plain text]
=head1 NAME
IO_Scalar_synopsis - test out IO::Scalar
=head1 SYNOPSIS
### From our distribution's top level directory:
perl -I./lib examples/IO_Scalar_synopsis
=cut
use 5.005;
use IO::Scalar;
use strict;
my $line = ('-' x 60)."\n";
my $somestring = "My message:\n";
print $line;
my $SH = new IO::Scalar \$somestring;
$SH->print("Hello");
$SH->print(", world!\nBye now!\n");
print "The string is now: ", $somestring, "\n";
print $line;
$SH = new IO::Scalar \$somestring;
while (defined($_ = $SH->getline)) {
print "Got line: $_";
}
$SH->close;
print $line;
$SH = new IO::Scalar \$somestring;
print "All lines:\n", $SH->getlines;
my $pos = $SH->getpos;
my $offset = $SH->tell;
$SH->setpos($pos);
$SH->seek($offset, 0);
print $line;
$SH = new IO::Scalar;
$SH->print("Hi there!");
print "I printed: ", ${$SH->sref}, "\n";
print $line;
$SH = new IO::Scalar \$somestring;
print $SH "Hello";
print $SH ", world!\nBye now!\n";
print "The string is now: ", $somestring, "\n";
print $line;
$SH = new IO::Scalar \$somestring;
while (<$SH>) {
print "Got line: $_";
}
close $SH;
print $line;
$SH = new IO::Scalar \$somestring;
print "All lines:\n", <$SH>;
$offset = tell $SH;
seek $SH, $offset, 0;
print $line;
$SH = new IO::Scalar;
print $SH "Hi there!";
print "I printed: ", ${$SH->sref}, "\n";
print $line;
my $str = "";
$SH = new IO::Scalar \$str;
print $SH "Hello, ";
print $SH "world!";
print "I printed: $SH\n";
1;