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