summaryrefslogtreecommitdiff
path: root/cpan/dist/IO-stringy/docs/IO/ScalarArray.pm.html
blob: 908a814bd4ce53b8753aec6ff8fe8c942df4e511 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<HTML>
<HEAD>
  <TITLE>IO::ScalarArray</TITLE>
</HEAD>
<BODY 
       bgcolor="#FFFFFF" link="#CC3366" vlink="#993366" alink="#FF6666">
<FONT FACE="sans-serif" SIZE=-1><A HREF="http://www.zeegee.com" TARGET="_top"><IMG SRC="icons/zeegee.gif" ALT="ZeeGee Software" ALIGN="RIGHT" BORDER="0"></A><A NAME="__TOP__"><H1>IO::ScalarArray</H1>
</A><UL>
<LI> <A HREF="#NAME">NAME</A>
<LI> <A HREF="#SYNOPSIS">SYNOPSIS</A>
<LI> <A HREF="#DESCRIPTION">DESCRIPTION</A>
<LI> <A HREF="#PUBLIC_INTERFACE">PUBLIC INTERFACE</A>
<UL>
<LI> <A HREF="#Construction">Construction</A>
<LI> <A HREF="#Input_and_output">Input and output</A>
<LI> <A HREF="#Seeking_telling_and_other_attributes">Seeking/telling and other attributes</A>
</UL>
<LI> <A HREF="#VERSION">VERSION</A>
<LI> <A HREF="#AUTHOR">AUTHOR</A>
<UL>
<LI> <A HREF="#Principal_author">Principal author</A>
<LI> <A HREF="#Other_contributors">Other contributors</A>
</UL>
</UL>
</A>

<P><HR>
<A NAME="NAME"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> NAME</H2></A>


<P>IO::ScalarArray - IO:: interface for reading/writing an array of scalars



<P><HR>
<A NAME="SYNOPSIS"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> SYNOPSIS</H2></A>


<P>If you have any Perl5, you can use the basic OO interface...

<FONT SIZE=3 FACE="courier"><PRE>
    use IO::ScalarArray;
    
    # Open a handle on an array-of-scalars:
    $AH = new IO::ScalarArray;
    $AH-&gt;open(\@a);
    
    # Open a handle on an array-of-scalars, read it line-by-line, 
    # then close it:
    $AH = new IO::ScalarArray \@a;
    while ($_ = $AH-&gt;getline) { print &quot;Line: $_&quot; }
    $AH-&gt;close;
        
    # Open a handle on an array-of-scalars, and slurp in all the lines:
    $AH = new IO::ScalarArray \@a;
    print $AH-&gt;getlines; 
     
    # Open a handle on an array-of-scalars, and append to it:
    $AH = new IO::ScalarArray \@a;
    $AH-&gt;print(&quot;bar\n&quot;);
    print &quot;some string is now: &quot;, $somestring, &quot;\n&quot;;
      
    # Get the current position:
    $pos = $AH-&gt;getpos;         ### $AH-&gt;tell() also works
     
    # Set the current position:
    $AH-&gt;setpos($pos);          ### $AH-&gt;seek(POS,WHENCE) also works
      
    # Open an anonymous temporary scalar array:
    $AH = new IO::ScalarArray;
    $AH-&gt;print(&quot;Hi there!\nHey there!\n&quot;);
    $AH-&gt;print(&quot;Ho there!\n&quot;);
    print &quot;I got: &quot;, @{$AH-&gt;aref}, &quot;\n&quot;;      ### get at value
</PRE></FONT>

<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:

<FONT SIZE=3 FACE="courier"><PRE>
    use IO::ScalarArray;
</PRE></FONT>
<FONT SIZE=3 FACE="courier"><PRE>
    # Writing to a scalar array...
    my @a; 
    tie *OUT, 'IO::ScalarArray', \@a;
    print OUT &quot;line 1\nline 2\n&quot;, &quot;line 3\n&quot;;
    print &quot;s is now... [&quot;, join('', @a), &quot;]\n&quot;; 
     
    # Reading and writing an anonymous scalar array... 
    tie *OUT, 'IO::ScalarArray';
    print OUT &quot;line 1\nline 2\n&quot;, &quot;line 3\n&quot;;
    tied(OUT)-&gt;seek(0,0);
    while (&lt;OUT&gt;) { print &quot;LINE: &quot;, $_ }
</PRE></FONT>


<P><HR>
<A NAME="DESCRIPTION"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> DESCRIPTION</H2></A>


<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>For writing large amounts of data with individual print() statements, 
this is likely to be more efficient than IO::Scalar.


<P>Basically, this:

<FONT SIZE=3 FACE="courier"><PRE>
    my @a;
    $AH = new IO::ScalarArray \@a;
    $AH-&gt;print(&quot;Hel&quot;, &quot;lo, &quot;);     
    $AH-&gt;print(&quot;world!\n&quot;);     
</PRE></FONT>

<P>Or this (if you have 5.004 or later):

<FONT SIZE=3 FACE="courier"><PRE>
    my @a;
    $AH = tie *OUT, 'IO::ScalarArray', \@a;
    print OUT &quot;Hel&quot;, &quot;lo, &quot;; 
    print OUT &quot;world!\n&quot;; 
</PRE></FONT>

<P>Causes @a to be set to the following arrayt of 3 strings:

<FONT SIZE=3 FACE="courier"><PRE>
    ( &quot;Hel&quot; , 
      &quot;lo, &quot; , 
      &quot;world!\n&quot; )
</PRE></FONT>

<P>Compare this with IO::Scalar.



<P><HR>
<A NAME="PUBLIC_INTERFACE"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> PUBLIC INTERFACE</H2></A>



<P><HR>
<A NAME="Construction"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Construction</H3></A>



<DL>
<P><DT><B><A NAME="item:new">new [ARGS...]</A></B></DT>
<DD>
<I>Class method.</I>
Return a new, unattached array handle.  
If any arguments are given, they're sent to open().

<P><DT><B><A NAME="item:open">open [ARRAYREF]</A></B></DT>
<DD>
<I>Instance method.</I>
Open the array handle on a new array, pointed to by ARRAYREF.
If no ARRAYREF is given, a &quot;private&quot; array is created to hold
the file data.


<P>Returns the self object on success, undefined on error.

<P><DT><B><A NAME="item:opened">opened</A></B></DT>
<DD>
<I>Instance method.</I>
Is the array handle opened on something?

<P><DT><B><A NAME="item:close">close</A></B></DT>
<DD>
<I>Instance method.</I>
Disassociate the array handle from its underlying array.
Done automatically on destroy.

</DL>



<P><HR>
<A NAME="Input_and_output"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Input and output</H3></A>



<DL>
<P><DT><B><A NAME="item:flush">flush</A></B></DT>
<DD>
<I>Instance method.</I>
No-op, provided for OO compatibility.

<P><DT><B><A NAME="item:getc">getc</A></B></DT>
<DD>
<I>Instance method.</I>
Return the next character, or undef if none remain.
This does a read(1), which is somewhat costly.

<P><DT><B><A NAME="item:getline">getline</A></B></DT>
<DD>
<I>Instance method.</I>
Return the next line, or undef on end of data.
Can safely be called in an array context.
Currently, lines are delimited by &quot;\n&quot;.

<P><DT><B><A NAME="item:getlines">getlines</A></B></DT>
<DD>
<I>Instance method.</I>
Get all remaining lines.
It will croak() if accidentally called in a scalar context.

<P><DT><B><A NAME="item:print">print ARGS...</A></B></DT>
<DD>
<I>Instance method.</I>
Print ARGS to the underlying array.  


<P>Currently, this always causes a &quot;seek to the end of the array&quot;
and generates a new array entry.  This may change in the future.

<P><DT><B><A NAME="item:read">read BUF, NBYTES, [OFFSET];</A></B></DT>
<DD>
<I>Instance method.</I>
Read some bytes from the array.
Returns the number of bytes actually read, 0 on end-of-file, undef on error.

<P><DT><B><A NAME="item:write">write BUF, NBYTES, [OFFSET];</A></B></DT>
<DD>
<I>Instance method.</I>
Write some bytes into the array.

</DL>



<P><HR>
<A NAME="Seeking_telling_and_other_attributes"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Seeking/telling and other attributes</H3></A>



<DL>
<P><DT><B><A NAME="item:autoflush">autoflush</A></B></DT>
<DD>
<I>Instance method.</I>
No-op, provided for OO compatibility.

<P><DT><B><A NAME="item:binmode">binmode</A></B></DT>
<DD>
<I>Instance method.</I>
No-op, provided for OO compatibility.

<P><DT><B><A NAME="item:clearerr">clearerr</A></B></DT>
<DD>
<I>Instance method.</I>  Clear the error and EOF flags.  A no-op.

<P><DT><B><A NAME="item:eof">eof</A></B></DT>
<DD>
<I>Instance method.</I>  Are we at end of file?

<P><DT><B><A NAME="item:seek">seek POS,WHENCE</A></B></DT>
<DD>
<I>Instance method.</I>
Seek to a given position in the stream.
Only a WHENCE of 0 (SEEK_SET) is supported.

<P><DT><B><A NAME="item:tell">tell</A></B></DT>
<DD>
<I>Instance method.</I>
Return the current position in the stream, as a numeric offset.

<P><DT><B><A NAME="item:setpos">setpos POS</A></B></DT>
<DD>
<I>Instance method.</I>
Seek to a given position in the array, using the opaque getpos() value.
Don't expect this to be a number.

<P><DT><B><A NAME="item:getpos">getpos</A></B></DT>
<DD>
<I>Instance method.</I>
Return the current position in the array, as an opaque value.
Don't expect this to be a number.

<P><DT><B><A NAME="item:aref">aref</A></B></DT>
<DD>
<I>Instance method.</I>
Return a reference to the underlying array.

</DL>



<P><HR>
<A NAME="VERSION"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> VERSION</H2></A>


<P>$Id: ScalarArray.pm,v 1.117 2000/09/28 06:32:28 eryq Exp $



<P><HR>
<A NAME="AUTHOR"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> AUTHOR</H2></A>



<P><HR>
<A NAME="Principal_author"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Principal author</H3></A>


<P>Eryq (<I><FILE><A HREF="mailto:eryq@zeegee.com">eryq@zeegee.com</A></FILE></I>).
President, ZeeGee Software Inc (<I><FILE><A HREF="http://www.zeegee.com">http://www.zeegee.com</A></FILE></I>).



<P><HR>
<A NAME="Other_contributors"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Other contributors</H3></A>


<P>Thanks to the following individuals for their invaluable contributions
(if I've forgotten or misspelled your name, please email me!):


<P><I>Andy Glew,</I>
for suggesting <CODE>getc()</CODE>.


<P><I>Brandon Browning,</I>
for suggesting <CODE>opened()</CODE>.


<P><I>Eric L. Brine,</I>
for his offset-using read() and write() implementations. 

<P><HR>
<ADDRESS><FONT SIZE=-1>
Generated Thu Sep 28 02:35:53 2000 by cvu_pod2html
</FONT></ADDRESS>
</FONT></BODY>
</HTML>