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

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>IO::Scalar - IO:: interface for reading/writing a scalar</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::Scalar - IO:: interface for reading/writing a scalar</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::Scalar - IO:: interface for reading/writing a scalar</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::Scalar;
  55. </PRE>
  56. <PRE>
  57.  
  58.     # Open a handle on a string:
  59.     $SH = new IO::Scalar;
  60.     $SH->open(\$somestring);</PRE>
  61. <PRE>
  62.  
  63.     # Open a handle on a string, read it line-by-line, then close it:
  64.     $SH = new IO::Scalar \$somestring;
  65.     while ($_ = $SH->getline) { print "Line: $_" }
  66.     $SH->close;</PRE>
  67. <PRE>
  68.  
  69.     # Open a handle on a string, and slurp in all the lines:
  70.     $SH = new IO::Scalar \$somestring;
  71.     print $SH->getlines;</PRE>
  72. <PRE>
  73.  
  74.     # Open a handle on a string, and append to it:
  75.     $SH = new IO::Scalar \$somestring
  76.     $SH->print("bar\n");        ### will add "bar\n" to the end</PRE>
  77. <PRE>
  78.  
  79.     # Get the current position:
  80.     $pos = $SH->getpos;         ### $SH->tell() also works</PRE>
  81. <PRE>
  82.  
  83.     # Set the current position:
  84.     $SH->setpos($pos);          ### $SH->seek(POS,WHENCE) also works</PRE>
  85. <PRE>
  86.  
  87.     # Open an anonymous temporary scalar:
  88.     $SH = new IO::Scalar;
  89.     $SH->print("Hi there!");
  90.     print "I got: ", ${$SH->sref}, "\n";      ### get at value</PRE>
  91. <P>If your Perl is 5.004 or later, you can use the TIEHANDLE
  92. interface, and read/write scalars just like files:</P>
  93. <PRE>
  94.     use IO::Scalar;</PRE>
  95. <PRE>
  96.     # Writing to a scalar...
  97.     my $s; 
  98.     tie *OUT, 'IO::Scalar', \$s;
  99.     print OUT "line 1\nline 2\n", "line 3\n";
  100.     print "s is now... $s\n"
  101. </PRE>
  102. <PRE>
  103.  
  104.     # Reading and writing an anonymous scalar... 
  105.     tie *OUT, 'IO::Scalar';
  106.     print OUT "line 1\nline 2\n", "line 3\n";
  107.     tied(OUT)->seek(0,0);
  108.     while (<OUT>) { print "LINE: ", $_ }</PRE>
  109. <P>
  110. <HR>
  111. <H1><A NAME="description">DESCRIPTION</A></H1>
  112. <P>This class implements objects which behave just like FileHandle
  113. (or IO::Handle) objects, except that you may use them to write to
  114. (or read from) scalars.  They can be tiehandle'd as well.</P>
  115. <P>Basically, this:</P>
  116. <PRE>
  117.     my $s;
  118.     $SH = new IO::Scalar \$s;
  119.     $SH->print("Hel", "lo, ");         # OO style
  120.     $SH->print("world!\n");            # ditto</PRE>
  121. <P>Or this (if you have 5.004 or later):</P>
  122. <PRE>
  123.     my $s;
  124.     $SH = tie *OUT, 'IO::Scalar', \$s;
  125.     print OUT "Hel", "lo, ";           # non-OO style
  126.     print OUT "world!\n";              # ditto</PRE>
  127. <P>Or this (if you have 5.004 or later):</P>
  128. <PRE>
  129.     my $s;
  130.     $SH = IO::Scalar->new_tie(\$s);
  131.     $SH->print("Hel", "lo, ");         # OO style...
  132.     print $SH "world!\n";              # ...or non-OO style!</PRE>
  133. <P>Causes $s to be set to:</P>
  134. <PRE>
  135.     "Hello, world!\n"</PRE>
  136. <P>
  137. <HR>
  138. <H1><A NAME="public interface">PUBLIC INTERFACE</A></H1>
  139. <P>
  140. <H2><A NAME="construction">Construction</A></H2>
  141. <DL>
  142. <DT><STRONG><A NAME="item_new_%5BARGS%2E%2E%2E%5D">new [ARGS...]</A></STRONG><BR>
  143. <DD>
  144. <EM>Class method.</EM>
  145. Return a new, unattached scalar handle.  
  146. If any arguments are given, they're sent to open().
  147. <P></P>
  148. <DT><STRONG><A NAME="item_open_%5BSCALARREF%5D">open [SCALARREF]</A></STRONG><BR>
  149. <DD>
  150. <EM>Instance method.</EM>
  151. Open the scalar handle on a new scalar, pointed to by SCALARREF.
  152. If no SCALARREF is given, a ``private'' scalar is created to hold
  153. the file data.
  154. <P>Returns the self object on success, undefined on error.</P>
  155. <P></P>
  156. <DT><STRONG><A NAME="item_opened">opened</A></STRONG><BR>
  157. <DD>
  158. <EM>Instance method.</EM>
  159. Is the scalar handle opened on something?
  160. <P></P>
  161. <DT><STRONG><A NAME="item_close">close</A></STRONG><BR>
  162. <DD>
  163. <EM>Instance method.</EM>
  164. Disassociate the scalar handle from its underlying scalar.
  165. Done automatically on destroy.
  166. <P></P></DL>
  167. <P>
  168. <H2><A NAME="input and output">Input and output</A></H2>
  169. <DL>
  170. <DT><STRONG><A NAME="item_getc">getc</A></STRONG><BR>
  171. <DD>
  172. <EM>Instance method.</EM>
  173. Return the next character, or undef if none remain.
  174. <P></P>
  175. <DT><STRONG><A NAME="item_getline">getline</A></STRONG><BR>
  176. <DD>
  177. <EM>Instance method.</EM>
  178. Return the next line, or undef on end of string.  
  179. Can safely be called in an array context.
  180. Currently, lines are delimited by ``\n''.
  181. <P></P>
  182. <DT><STRONG><A NAME="item_getlines">getlines</A></STRONG><BR>
  183. <DD>
  184. <EM>Instance method.</EM>
  185. Get all remaining lines.
  186. It will <CODE>croak()</CODE> if accidentally called in a scalar context.
  187. <P></P>
  188. <DT><STRONG><A NAME="item_print_ARGS%2E%2E%2E">print ARGS...</A></STRONG><BR>
  189. <DD>
  190. <EM>Instance method.</EM>
  191. Print ARGS to the underlying scalar.
  192. <P><STRONG>Warning:</STRONG> Currently, this always causes a ``seek to the end of the string''; 
  193. this may change in the future.</P>
  194. <P></P>
  195. <DT><STRONG><A NAME="item_read_BUF%2C_NBYTES%2C_%5BOFFSET%5D">read BUF, NBYTES, [OFFSET]</A></STRONG><BR>
  196. <DD>
  197. <EM>Instance method.</EM>
  198. Read some bytes from the scalar.
  199. Returns the number of bytes actually read, 0 on end-of-file, undef on error.
  200. <P></P></DL>
  201. <P>
  202. <H2><A NAME="seeking and telling">Seeking and telling</A></H2>
  203. <DL>
  204. <DT><STRONG><A NAME="item_clearerr">clearerr</A></STRONG><BR>
  205. <DD>
  206. <EM>Instance method.</EM>  Clear the error and EOF flags.  A no-op.
  207. <P></P>
  208. <DT><STRONG><A NAME="item_eof">eof</A></STRONG><BR>
  209. <DD>
  210. <EM>Instance method.</EM>  Are we at end of file?
  211. <P></P>
  212. <DT><STRONG><A NAME="item_seek">seek OFFSET, WHENCE</A></STRONG><BR>
  213. <DD>
  214. <EM>Instance method.</EM>  Seek to a given position in the stream.
  215. <P></P>
  216. <DT><STRONG><A NAME="item_tell">tell</A></STRONG><BR>
  217. <DD>
  218. <EM>Instance method.</EM>
  219. Return the current position in the stream, as a numeric offset.
  220. <P></P>
  221. <DT><STRONG><A NAME="item_setpos">setpos POS</A></STRONG><BR>
  222. <DD>
  223. <EM>Instance method.</EM>
  224. Set the current position, using the opaque value returned by <A HREF="#item_getpos"><CODE>getpos()</CODE></A>.
  225. <P></P>
  226. <DT><STRONG><A NAME="item_getpos">getpos</A></STRONG><BR>
  227. <DD>
  228. <EM>Instance method.</EM>
  229. Return the current position in the string, as an opaque object.
  230. <P></P>
  231. <DT><STRONG><A NAME="item_sref">sref</A></STRONG><BR>
  232. <DD>
  233. <EM>Instance method.</EM>
  234. Return a reference to the underlying scalar.
  235. <P></P></DL>
  236. <P>
  237. <HR>
  238. <H1><A NAME="version">VERSION</A></H1>
  239. <P>$Id: Scalar.pm,v 1.114 1998/12/16 02:00:04 eryq Exp $</P>
  240. <P>
  241. <HR>
  242. <H1><A NAME="author">AUTHOR</A></H1>
  243. <P>Eryq (<EM><A HREF="mailto:eryq@zeegee.com">eryq@zeegee.com</A></EM>).
  244. President, ZeeGee Software Inc (<EM><A HREF="http://www.zeegee.com">http://www.zeegee.com</A></EM>).</P>
  245. <P>Thanks to Andy Glew for contributing <A HREF="#item_getc"><CODE>getc()</CODE></A>.</P>
  246. <P>Thanks to Brandon Browning for suggesting <A HREF="#item_opened"><CODE>opened()</CODE></A>.</P>
  247. <P>Thanks to David Richter for finding and fixing the bug in <CODE>PRINTF()</CODE>.</P>
  248. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  249. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  250. <STRONG><P CLASS=block> IO::Scalar - IO:: interface for reading/writing a scalar</P></STRONG>
  251. </TD></TR>
  252. </TABLE>
  253.  
  254. </BODY>
  255.  
  256. </HTML>
  257.