home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>IO::Scalar - IO:: interface for reading/writing a scalar</TITLE>
- <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> IO::Scalar - IO:: interface for reading/writing a scalar</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- <LI><A HREF="#public interface">PUBLIC INTERFACE</A></LI>
- <UL>
-
- <LI><A HREF="#construction">Construction</A></LI>
- <LI><A HREF="#input and output">Input and output</A></LI>
- <LI><A HREF="#seeking and telling">Seeking and telling</A></LI>
- </UL>
-
- <LI><A HREF="#version">VERSION</A></LI>
- <LI><A HREF="#author">AUTHOR</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>IO::Scalar - IO:: interface for reading/writing a scalar</P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <P>If you have any Perl5, you can use the basic OO interface...</P>
- <PRE>
- use IO::Scalar;
- </PRE>
- <PRE>
-
- # Open a handle on a string:
- $SH = new IO::Scalar;
- $SH->open(\$somestring);</PRE>
- <PRE>
-
- # Open a handle on a string, read it line-by-line, then close it:
- $SH = new IO::Scalar \$somestring;
- while ($_ = $SH->getline) { print "Line: $_" }
- $SH->close;</PRE>
- <PRE>
-
- # Open a handle on a string, and slurp in all the lines:
- $SH = new IO::Scalar \$somestring;
- print $SH->getlines;</PRE>
- <PRE>
-
- # Open a handle on a string, and append to it:
- $SH = new IO::Scalar \$somestring
- $SH->print("bar\n"); ### will add "bar\n" to the end</PRE>
- <PRE>
-
- # Get the current position:
- $pos = $SH->getpos; ### $SH->tell() also works</PRE>
- <PRE>
-
- # Set the current position:
- $SH->setpos($pos); ### $SH->seek(POS,WHENCE) also works</PRE>
- <PRE>
-
- # Open an anonymous temporary scalar:
- $SH = new IO::Scalar;
- $SH->print("Hi there!");
- print "I got: ", ${$SH->sref}, "\n"; ### get at value</PRE>
- <P>If your Perl is 5.004 or later, you can use the TIEHANDLE
- interface, and read/write scalars just like files:</P>
- <PRE>
- use IO::Scalar;</PRE>
- <PRE>
- # Writing to a scalar...
- my $s;
- tie *OUT, 'IO::Scalar', \$s;
- print OUT "line 1\nline 2\n", "line 3\n";
- print "s is now... $s\n"
- </PRE>
- <PRE>
-
- # Reading and writing an anonymous scalar...
- tie *OUT, 'IO::Scalar';
- print OUT "line 1\nline 2\n", "line 3\n";
- tied(OUT)->seek(0,0);
- while (<OUT>) { print "LINE: ", $_ }</PRE>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>This class implements objects which behave just like FileHandle
- (or IO::Handle) objects, except that you may use them to write to
- (or read from) scalars. They can be tiehandle'd as well.</P>
- <P>Basically, this:</P>
- <PRE>
- my $s;
- $SH = new IO::Scalar \$s;
- $SH->print("Hel", "lo, "); # OO style
- $SH->print("world!\n"); # ditto</PRE>
- <P>Or this (if you have 5.004 or later):</P>
- <PRE>
- my $s;
- $SH = tie *OUT, 'IO::Scalar', \$s;
- print OUT "Hel", "lo, "; # non-OO style
- print OUT "world!\n"; # ditto</PRE>
- <P>Or this (if you have 5.004 or later):</P>
- <PRE>
- my $s;
- $SH = IO::Scalar->new_tie(\$s);
- $SH->print("Hel", "lo, "); # OO style...
- print $SH "world!\n"; # ...or non-OO style!</PRE>
- <P>Causes $s to be set to:</P>
- <PRE>
- "Hello, world!\n"</PRE>
- <P>
- <HR>
- <H1><A NAME="public interface">PUBLIC INTERFACE</A></H1>
- <P>
- <H2><A NAME="construction">Construction</A></H2>
- <DL>
- <DT><STRONG><A NAME="item_new_%5BARGS%2E%2E%2E%5D">new [ARGS...]</A></STRONG><BR>
- <DD>
- <EM>Class method.</EM>
- Return a new, unattached scalar handle.
- If any arguments are given, they're sent to open().
- <P></P>
- <DT><STRONG><A NAME="item_open_%5BSCALARREF%5D">open [SCALARREF]</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Open the scalar handle on a new scalar, pointed to by SCALARREF.
- If no SCALARREF is given, a ``private'' scalar is created to hold
- the file data.
- <P>Returns the self object on success, undefined on error.</P>
- <P></P>
- <DT><STRONG><A NAME="item_opened">opened</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Is the scalar handle opened on something?
- <P></P>
- <DT><STRONG><A NAME="item_close">close</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Disassociate the scalar handle from its underlying scalar.
- Done automatically on destroy.
- <P></P></DL>
- <P>
- <H2><A NAME="input and output">Input and output</A></H2>
- <DL>
- <DT><STRONG><A NAME="item_getc">getc</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Return the next character, or undef if none remain.
- <P></P>
- <DT><STRONG><A NAME="item_getline">getline</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Return the next line, or undef on end of string.
- Can safely be called in an array context.
- Currently, lines are delimited by ``\n''.
- <P></P>
- <DT><STRONG><A NAME="item_getlines">getlines</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Get all remaining lines.
- It will <CODE>croak()</CODE> if accidentally called in a scalar context.
- <P></P>
- <DT><STRONG><A NAME="item_print_ARGS%2E%2E%2E">print ARGS...</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Print ARGS to the underlying scalar.
- <P><STRONG>Warning:</STRONG> Currently, this always causes a ``seek to the end of the string'';
- this may change in the future.</P>
- <P></P>
- <DT><STRONG><A NAME="item_read_BUF%2C_NBYTES%2C_%5BOFFSET%5D">read BUF, NBYTES, [OFFSET]</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Read some bytes from the scalar.
- Returns the number of bytes actually read, 0 on end-of-file, undef on error.
- <P></P></DL>
- <P>
- <H2><A NAME="seeking and telling">Seeking and telling</A></H2>
- <DL>
- <DT><STRONG><A NAME="item_clearerr">clearerr</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM> Clear the error and EOF flags. A no-op.
- <P></P>
- <DT><STRONG><A NAME="item_eof">eof</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM> Are we at end of file?
- <P></P>
- <DT><STRONG><A NAME="item_seek">seek OFFSET, WHENCE</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM> Seek to a given position in the stream.
- <P></P>
- <DT><STRONG><A NAME="item_tell">tell</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Return the current position in the stream, as a numeric offset.
- <P></P>
- <DT><STRONG><A NAME="item_setpos">setpos POS</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Set the current position, using the opaque value returned by <A HREF="#item_getpos"><CODE>getpos()</CODE></A>.
- <P></P>
- <DT><STRONG><A NAME="item_getpos">getpos</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Return the current position in the string, as an opaque object.
- <P></P>
- <DT><STRONG><A NAME="item_sref">sref</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Return a reference to the underlying scalar.
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="version">VERSION</A></H1>
- <P>$Id: Scalar.pm,v 1.114 1998/12/16 02:00:04 eryq Exp $</P>
- <P>
- <HR>
- <H1><A NAME="author">AUTHOR</A></H1>
- <P>Eryq (<EM><A HREF="mailto:eryq@zeegee.com">eryq@zeegee.com</A></EM>).
- President, ZeeGee Software Inc (<EM><A HREF="http://www.zeegee.com">http://www.zeegee.com</A></EM>).</P>
- <P>Thanks to Andy Glew for contributing <A HREF="#item_getc"><CODE>getc()</CODE></A>.</P>
- <P>Thanks to Brandon Browning for suggesting <A HREF="#item_opened"><CODE>opened()</CODE></A>.</P>
- <P>Thanks to David Richter for finding and fixing the bug in <CODE>PRINTF()</CODE>.</P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> IO::Scalar - IO:: interface for reading/writing a scalar</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-