home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>IO::ScalarArray - IO:: interface for reading/writing an array of scalars</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::ScalarArray - IO:: interface for reading/writing an array of scalars</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::ScalarArray - IO:: interface for reading/writing an array of scalars</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::ScalarArray;
- </PRE>
- <PRE>
-
- # Open a handle on an array-of-scalars:
- $AH = new IO::ScalarArray;
- $AH->open(\@a);</PRE>
- <PRE>
-
- # Open a handle on an array-of-scalars, read it line-by-line,
- # then close it:
- $AH = new IO::ScalarArray \@a;
- while ($_ = $AH->getline) { print "Line: $_" }
- $AH->close;</PRE>
- <PRE>
-
- # Open a handle on an array-of-scalars, and slurp in all the lines:
- $AH = new IO::ScalarArray \@a;
- print $AH->getlines;</PRE>
- <PRE>
-
- # Open a handle on an array-of-scalars, and append to it:
- $AH = new IO::ScalarArray \@a;
- $AH->print("bar\n");
- print "some string is now: ", $somestring, "\n";</PRE>
- <PRE>
-
- # Get the current position:
- $pos = $AH->getpos; ### $AH->tell() also works</PRE>
- <PRE>
-
- # Set the current position:
- $AH->setpos($pos); ### $AH->seek(POS,WHENCE) also works</PRE>
- <PRE>
-
- # Open an anonymous temporary scalar array:
- $AH = new IO::ScalarArray;
- $AH->print("Hi there!\nHey there!\n");
- $AH->print("Ho there!\n");
- print "I got: ", @{$AH->aref}, "\n"; ### get at value</PRE>
- <P>If your Perl is 5.004 or later, you can use the TIEHANDLE
- interface, and read/write as array-of-scalars just like files:</P>
- <PRE>
- use IO::ScalarArray;</PRE>
- <PRE>
- # Writing to a scalar array...
- my @a;
- tie *OUT, 'IO::ScalarArray', \@a;
- print OUT "line 1\nline 2\n", "line 3\n";
- print "s is now... [", join('', @a), "]\n";
- </PRE>
- <PRE>
-
- # Reading and writing an anonymous scalar array...
- tie *OUT, 'IO::ScalarArray';
- 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>For writing large amounts of data with individual <A HREF="../../../lib/Pod/perlfunc.html#item_print"><CODE>print()</CODE></A> statements,
- this is likely to be more efficient than IO::Scalar.</P>
- <P>Basically, this:</P>
- <PRE>
- my @a;
- $AH = new IO::ScalarArray \@a;
- $AH->print("Hel", "lo, ");
- $AH->print("world!\n");</PRE>
- <P>Or this (if you have 5.004 or later):</P>
- <PRE>
- my @a;
- $AH = tie *OUT, 'IO::ScalarArray', \@a;
- print OUT "Hel", "lo, ";
- print OUT "world!\n";</PRE>
- <P>Causes @a to be set to the following arrayt of 3 strings:</P>
- <PRE>
- ( "Hel" ,
- "lo, " ,
- "world!\n" )</PRE>
- <P>Compare this with IO::Scalar.</P>
- <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 array handle.
- If any arguments are given, they're sent to open().
- <P></P>
- <DT><STRONG><A NAME="item_open_%5BARRAYREF%5D">open [ARRAYREF]</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Open the array handle on a new array, pointed to by ARRAYREF.
- If no ARRAYREF is given, a ``private'' array 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 array handle opened on something?
- <P></P>
- <DT><STRONG><A NAME="item_close">close</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Disassociate the array handle from its underlying array.
- 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.
- This does a read(1), which is somewhat costly.
- <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 data.
- 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 array.
- <P>Currently, this always causes a ``seek to the end of the array''
- and generates a new array entry. This may change in the future.</P>
- <P></P>
- <DT><STRONG><A NAME="item_read_BUF%2C_NBYTES%2C_%5BOFFSET%5D%3B">read BUF, NBYTES, [OFFSET];</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Read some bytes from the array.
- 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_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 POS,WHENCE</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Seek to a given position in the stream.
- Only a WHENCE of 0 (SEEK_SET) is supported.
- <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>
- Seek to a given position in the array, using the opaque <A HREF="#item_getpos"><CODE>getpos()</CODE></A> value.
- Don't expect this to be a number.
- <P></P>
- <DT><STRONG><A NAME="item_getpos">getpos</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Return the current position in the array, as an opaque value.
- Don't expect this to be a number.
- <P></P>
- <DT><STRONG><A NAME="item_aref">aref</A></STRONG><BR>
- <DD>
- <EM>Instance method.</EM>
- Return a reference to the underlying array.
- <P></P></DL>
- <P>
- <HR>
- <H1><A NAME="version">VERSION</A></H1>
- <P>$Id: ScalarArray.pm,v 1.112 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 suggesting <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>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> IO::ScalarArray - IO:: interface for reading/writing an array of scalars</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-