home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _bd89dedf195adbfd260a08566a770631 < prev    next >
Text File  |  2000-03-23  |  9KB  |  259 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>IO::ScalarArray - IO:: interface for reading/writing an array of scalars</TITLE>
  5. <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> IO::ScalarArray - IO:: interface for reading/writing an array of scalars</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <LI><A HREF="#public interface">PUBLIC INTERFACE</A></LI>
  26.     <UL>
  27.  
  28.         <LI><A HREF="#construction">Construction</A></LI>
  29.         <LI><A HREF="#input and output">Input and output</A></LI>
  30.         <LI><A HREF="#seeking and telling">Seeking and telling</A></LI>
  31.     </UL>
  32.  
  33.     <LI><A HREF="#version">VERSION</A></LI>
  34.     <LI><A HREF="#author">AUTHOR</A></LI>
  35. </UL>
  36. <!-- INDEX END -->
  37.  
  38. <HR>
  39. <P>
  40. <H1><A NAME="name">NAME</A></H1>
  41. <P>IO::ScalarArray - IO:: interface for reading/writing an array of scalars</P>
  42. <P>
  43. <HR>
  44. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  45. <UL>
  46. <LI>Linux</LI>
  47. <LI>Solaris</LI>
  48. <LI>Windows</LI>
  49. </UL>
  50. <HR>
  51. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  52. <P>If you have any Perl5, you can use the basic OO interface...</P>
  53. <PRE>
  54.     use IO::ScalarArray;
  55. </PRE>
  56. <PRE>
  57.  
  58.     # Open a handle on an array-of-scalars:
  59.     $AH = new IO::ScalarArray;
  60.     $AH->open(\@a);</PRE>
  61. <PRE>
  62.  
  63.     # Open a handle on an array-of-scalars, read it line-by-line, 
  64.     # then close it:
  65.     $AH = new IO::ScalarArray \@a;
  66.     while ($_ = $AH->getline) { print "Line: $_" }
  67.     $AH->close;</PRE>
  68. <PRE>
  69.  
  70.     # Open a handle on an array-of-scalars, and slurp in all the lines:
  71.     $AH = new IO::ScalarArray \@a;
  72.     print $AH->getlines;</PRE>
  73. <PRE>
  74.  
  75.     # Open a handle on an array-of-scalars, and append to it:
  76.     $AH = new IO::ScalarArray \@a;
  77.     $AH->print("bar\n");
  78.     print "some string is now: ", $somestring, "\n";</PRE>
  79. <PRE>
  80.  
  81.     # Get the current position:
  82.     $pos = $AH->getpos;         ### $AH->tell() also works</PRE>
  83. <PRE>
  84.  
  85.     # Set the current position:
  86.     $AH->setpos($pos);          ### $AH->seek(POS,WHENCE) also works</PRE>
  87. <PRE>
  88.  
  89.     # Open an anonymous temporary scalar array:
  90.     $AH = new IO::ScalarArray;
  91.     $AH->print("Hi there!\nHey there!\n");
  92.     $AH->print("Ho there!\n");
  93.     print "I got: ", @{$AH->aref}, "\n";      ### get at value</PRE>
  94. <P>If your Perl is 5.004 or later, you can use the TIEHANDLE
  95. interface, and read/write as array-of-scalars just like files:</P>
  96. <PRE>
  97.     use IO::ScalarArray;</PRE>
  98. <PRE>
  99.     # Writing to a scalar array...
  100.     my @a; 
  101.     tie *OUT, 'IO::ScalarArray', \@a;
  102.     print OUT "line 1\nline 2\n", "line 3\n";
  103.     print "s is now... [", join('', @a), "]\n"; 
  104. </PRE>
  105. <PRE>
  106.  
  107.     # Reading and writing an anonymous scalar array... 
  108.     tie *OUT, 'IO::ScalarArray';
  109.     print OUT "line 1\nline 2\n", "line 3\n";
  110.     tied(OUT)->seek(0,0);
  111.     while (<OUT>) { print "LINE: ", $_ }</PRE>
  112. <P>
  113. <HR>
  114. <H1><A NAME="description">DESCRIPTION</A></H1>
  115. <P>This class implements objects which behave just like FileHandle
  116. (or IO::Handle) objects, except that you may use them to write to
  117. (or read from) scalars.  They can be tiehandle'd as well.</P>
  118. <P>For writing large amounts of data with individual <A HREF="../../../lib/Pod/perlfunc.html#item_print"><CODE>print()</CODE></A> statements, 
  119. this is likely to be more efficient than IO::Scalar.</P>
  120. <P>Basically, this:</P>
  121. <PRE>
  122.     my @a;
  123.     $AH = new IO::ScalarArray \@a;
  124.     $AH->print("Hel", "lo, ");     
  125.     $AH->print("world!\n");</PRE>
  126. <P>Or this (if you have 5.004 or later):</P>
  127. <PRE>
  128.     my @a;
  129.     $AH = tie *OUT, 'IO::ScalarArray', \@a;
  130.     print OUT "Hel", "lo, "; 
  131.     print OUT "world!\n";</PRE>
  132. <P>Causes @a to be set to the following arrayt of 3 strings:</P>
  133. <PRE>
  134.     ( "Hel" , 
  135.       "lo, " , 
  136.       "world!\n" )</PRE>
  137. <P>Compare this with IO::Scalar.</P>
  138. <P>
  139. <HR>
  140. <H1><A NAME="public interface">PUBLIC INTERFACE</A></H1>
  141. <P>
  142. <H2><A NAME="construction">Construction</A></H2>
  143. <DL>
  144. <DT><STRONG><A NAME="item_new_%5BARGS%2E%2E%2E%5D">new [ARGS...]</A></STRONG><BR>
  145. <DD>
  146. <EM>Class method.</EM>
  147. Return a new, unattached array handle.  
  148. If any arguments are given, they're sent to open().
  149. <P></P>
  150. <DT><STRONG><A NAME="item_open_%5BARRAYREF%5D">open [ARRAYREF]</A></STRONG><BR>
  151. <DD>
  152. <EM>Instance method.</EM>
  153. Open the array handle on a new array, pointed to by ARRAYREF.
  154. If no ARRAYREF is given, a ``private'' array is created to hold
  155. the file data.
  156. <P>Returns the self object on success, undefined on error.</P>
  157. <P></P>
  158. <DT><STRONG><A NAME="item_opened">opened</A></STRONG><BR>
  159. <DD>
  160. <EM>Instance method.</EM>
  161. Is the array handle opened on something?
  162. <P></P>
  163. <DT><STRONG><A NAME="item_close">close</A></STRONG><BR>
  164. <DD>
  165. <EM>Instance method.</EM>
  166. Disassociate the array handle from its underlying array.
  167. Done automatically on destroy.
  168. <P></P></DL>
  169. <P>
  170. <H2><A NAME="input and output">Input and output</A></H2>
  171. <DL>
  172. <DT><STRONG><A NAME="item_getc">getc</A></STRONG><BR>
  173. <DD>
  174. <EM>Instance method.</EM>
  175. Return the next character, or undef if none remain.
  176. This does a read(1), which is somewhat costly.
  177. <P></P>
  178. <DT><STRONG><A NAME="item_getline">getline</A></STRONG><BR>
  179. <DD>
  180. <EM>Instance method.</EM>
  181. Return the next line, or undef on end of data.
  182. Can safely be called in an array context.
  183. Currently, lines are delimited by ``\n''.
  184. <P></P>
  185. <DT><STRONG><A NAME="item_getlines">getlines</A></STRONG><BR>
  186. <DD>
  187. <EM>Instance method.</EM>
  188. Get all remaining lines.
  189. It will <CODE>croak()</CODE> if accidentally called in a scalar context.
  190. <P></P>
  191. <DT><STRONG><A NAME="item_print_ARGS%2E%2E%2E">print ARGS...</A></STRONG><BR>
  192. <DD>
  193. <EM>Instance method.</EM>
  194. Print ARGS to the underlying array.
  195. <P>Currently, this always causes a ``seek to the end of the array''
  196. and generates a new array entry.  This may change in the future.</P>
  197. <P></P>
  198. <DT><STRONG><A NAME="item_read_BUF%2C_NBYTES%2C_%5BOFFSET%5D%3B">read BUF, NBYTES, [OFFSET];</A></STRONG><BR>
  199. <DD>
  200. <EM>Instance method.</EM>
  201. Read some bytes from the array.
  202. Returns the number of bytes actually read, 0 on end-of-file, undef on error.
  203. <P></P></DL>
  204. <P>
  205. <H2><A NAME="seeking and telling">Seeking and telling</A></H2>
  206. <DL>
  207. <DT><STRONG><A NAME="item_eof">eof</A></STRONG><BR>
  208. <DD>
  209. <EM>Instance method.</EM>  Are we at end of file?
  210. <P></P>
  211. <DT><STRONG><A NAME="item_seek">seek POS,WHENCE</A></STRONG><BR>
  212. <DD>
  213. <EM>Instance method.</EM>
  214. Seek to a given position in the stream.
  215. Only a WHENCE of 0 (SEEK_SET) is supported.
  216. <P></P>
  217. <DT><STRONG><A NAME="item_tell">tell</A></STRONG><BR>
  218. <DD>
  219. <EM>Instance method.</EM>
  220. Return the current position in the stream, as a numeric offset.
  221. <P></P>
  222. <DT><STRONG><A NAME="item_setpos">setpos POS</A></STRONG><BR>
  223. <DD>
  224. <EM>Instance method.</EM>
  225. Seek to a given position in the array, using the opaque <A HREF="#item_getpos"><CODE>getpos()</CODE></A> value.
  226. Don't expect this to be a number.
  227. <P></P>
  228. <DT><STRONG><A NAME="item_getpos">getpos</A></STRONG><BR>
  229. <DD>
  230. <EM>Instance method.</EM>
  231. Return the current position in the array, as an opaque value.
  232. Don't expect this to be a number.
  233. <P></P>
  234. <DT><STRONG><A NAME="item_aref">aref</A></STRONG><BR>
  235. <DD>
  236. <EM>Instance method.</EM>
  237. Return a reference to the underlying array.
  238. <P></P></DL>
  239. <P>
  240. <HR>
  241. <H1><A NAME="version">VERSION</A></H1>
  242. <P>$Id: ScalarArray.pm,v 1.112 1998/12/16 02:00:04 eryq Exp $</P>
  243. <P>
  244. <HR>
  245. <H1><A NAME="author">AUTHOR</A></H1>
  246. <P>Eryq (<EM><A HREF="mailto:eryq@zeegee.com">eryq@zeegee.com</A></EM>).
  247. President, ZeeGee Software Inc (<EM><A HREF="http://www.zeegee.com">http://www.zeegee.com</A></EM>).</P>
  248. <P>Thanks to Andy Glew for suggesting <A HREF="#item_getc"><CODE>getc()</CODE></A>.</P>
  249. <P>Thanks to Brandon Browning for suggesting <A HREF="#item_opened"><CODE>opened()</CODE></A>.</P>
  250. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  251. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  252. <STRONG><P CLASS=block> IO::ScalarArray - IO:: interface for reading/writing an array of scalars</P></STRONG>
  253. </TD></TR>
  254. </TABLE>
  255.  
  256. </BODY>
  257.  
  258. </HTML>
  259.