1Fsdb::IO::Reader(3)   User Contributed Perl Documentation  Fsdb::IO::Reader(3)
2
3
4

NAME

6       Fsdb::IO::Reader - handle formatting reading from a fsdb file (handle)
7       or queue
8

SAMPLE CODE

10       Sample code reading an input stream:
11
12           $in = new Fsdb::IO::Reader(-file => '-');
13           $in->error and die "cannot open stdin as fsdb: " . $in->error . "\n";
14           my @arow;
15           while ($in->read_row_to_aref(\@arow) {
16               # do something
17           };
18           $in->close;
19

METHODS

21   new
22           $fsdb = new Fsdb::IO::Reader(-file => $filename);
23           $fsdb = new Fsdb::IO::Reader(-header => "#fsdb -F t foo bar", -fh => $file_handle);
24
25       Creates a new reader object from FILENAME.  (FILENAME can also be a
26       IO::Handle object.)  Always succeeds, but check the "error" method to
27       test for failure.
28
29       Options:
30
31       other options See also the options in Fsdb::IO, including "-file",
32       "-header".
33       -file FILENAME Open and read the given filename.
34       -comment_handler $ref
35           Define how comments are handled.  If $REF is a Fsdb::IO::Writer
36           object, comments are written to that stream as they are
37           encountered.  if $REF is a ref to a scalar, then we assume that
38           scalar will be filled in with a Fsdb::IO::Writer object later and
39           treat it the same.  If it is of type code, then it is assumed to be
40           a callback function of the form:
41
42               sub comment_handler ($) { my $comment = @_; }
43
44           where the one argument will be a string with the unparsed comment
45           (with leading # and trailing newline).
46
47           By default, or if $ref is undef, comments are consumed.
48
49           A typical handler if you have an output Fsdb stream is:
50
51               sub { $out->write_raw(@_); };
52
53           (That is the code created by
54           Fsdb::Filter::create_pass_comments_sub.)
55
56           There are several support routines to handle comments in a
57           pipeline; see Fsdb::Filter::create_pass_comments_sub,
58           Fsdb::Filter::create_tolerant_pass_comments_sub,
59           Fsdb::Filter::create_delay_comments_sub.
60
61       User-specified -header arguments override a header provided in the
62       input source.
63
64   config_one
65       documented in new
66
67   comment_handler_to_sub;
68       internal use only: parses and sets up the comment handle callback.  (At
69       input, _comment_sub is as given by -comment_handler, but at exit it is
70       always an anon function.
71
72   _enable_compression
73           $self->_enable_compression
74
75       internal use only: switch from uncompressed to compressed.
76
77   create_io_subs
78           $self->create_io_subs()
79
80       internal use only: create a thunk that returns rowobjs.
81
82   read_headerrow
83       internal use only; reads the header
84
85   read_rowobj
86           $rowobj = $fsdb->read_rowobj;
87
88       Reads a line of input and returns a "row object", either a scalar
89       string for a comment or header, or an array reference for a row, or
90       undef on end-of-stream.  This routine is the fastest way to do full-
91       featured fsdb-formatted IO.  (Although see also
92       Fsdb::Reader::fastpath_sub.)
93
94       Unlike all the other routines (including fastpath_sub), read_rowobj
95       does not do comment processing (calling comment_sub).
96
97   read_row_to_aref
98           $fsdb->read_row_to_aref(\@a);
99
100       Then $a[0] is the 0th column, etc.  Returns undef if the read fails,
101       typically due to EOF.
102
103   unread_rowobj
104           $fsdb->unread_rowobj($fref)
105
106       Put an fref back into the stream.
107
108   unread_row_from_aref
109           $fsdb->unread_row_from_aref(\@a);
110
111       Put array @a back into the file.
112
113   read_row_to_href
114           $fsdb->read_row_to_href(\%h);
115
116       Read the next row into hash %h.  Then $h{'colname'} is the value of
117       that column.  Returns undef if the read fails, typically due to EOF.
118
119   unread_row_from_href
120           $fsdb->unread_row_from_href(\%h);
121
122       Put hash %h back into the file.
123
124   fastpath_ok
125           $fsdb->fastpath_ok();
126
127       Check if we can do fast-path IO (post-header, no pending unread rows,
128       no errors).
129
130   fastpath_sub
131           $sub = $fsdb->fastpath_sub()
132           $row_aref = &$sub();
133
134       Return an anonymous sub that does read fast-path when called.  This
135       code stub returns a new $aref corresponding with a data line, and
136       handles comments as specified by -comment_handler
137
138
139
140perl v5.28.1                      2018-12-19               Fsdb::IO::Reader(3)
Impressum