Fsdb::IO::Writer(3)
π NAME π
Fsdb::IO::Writer β bestie, this is the module that handles formatting when you're writing out to a fsdb file (the handle) or a queue. It's the output side of the whole situation π
β¨ new β¨
$fsdb = new Fsdb::IO::Writer(-file => $filename);
$fsdb = new Fsdb::IO::Writer(-header => "#fsdb -F t foo bar",
-fh => $file_handle);
$fsdb = new Fsdb::IO::Writer(-file => '-',
-fscode => 'S',
-cols => [qw(firstcol second)]);
# or to add a column to a prior file
$in = new Fsdb::IO::Reader(-file => '-');
$out = new Fsdb::IO::Writer(-clone => $in, -outputheader => 'delay');
$out->col_create('new_column');
okay so this makes you a brand new writer object π¦ and the vibe is: it always succeeds, which is kinda iconic but also lowkey a trap β so you gotta check the error method to see if it actually failed fr fr.
Options, bestie:
- other options β peep the options over in
Fsdb::IO, including-fileand-headertoo π -file FILENAMEβ opens and writes to the filename you give it. The special filename-means standard output, and any files withhdfs:get written out to Hadoop. slay π-outputheader [now|delay|never|&format_sub]β controls when the header shows up:nowβ the default! the header is generated right after option parsing β¨delayβ nope, it waits and gets generated on the first data record that's output β³neverβ no header is ever output, which means your output is then not fsdb format anymore π (fair warning, bestie)- a perl subroutine β then
format_sub()gets called to generate the header on the first data record output (just likedelay), and it should return the string for the header π«Ά
π§ config_one
documented in new β yeah babe, go look up there β¬οΈ
π _enable_compression
$self->_enable_compression
internal use only: switches from uncompressed to compressed. not your business, respectfully π₯
πΈ create_io_subs
$self->create_io_subs($with_compression)
internal use only: builds a thunk that writes rowobjs π
β write_headerrow
internal use only; writes the header.
plot twist: as a side-effect, we also instantiate the _write_io_sub π
π write_rowobj
$fsdb->write_rowobj($rowobj);
writes a "row object" out to an output stream. a row object is either a scalar string (for a comment or a header) or an array reference for a row. this routine is literally the fastest way to do full-featured fsdb-formatted IO π (though also go peek at Fsdb::Writer::fastpath_sub, iykyk)
π¦ write_row_from_aref
$fsdb->write_row_from_aref(\@a);
writes @a out. that's it, that's the whole thing β¨
π write_row
$fsdb->write_row($a1, $a2...);
writes the args out. fair warning though: this is less efficient than write_row_from_aref, so like... know that about it π«
π write_row_from_href
$fsdb->write_row_from_href(\%h);
writes out %h, which is a hash of the row fields where every key is a field name π
π§ fastpath_ok
$fsdb->fastpath_ok();
checks whether we can do the fast-path IO (header's written, no errors anywhere) β a lil vibe check before you commit π
π fastpath_sub
$fsdb->fastpath_sub()
returns an anonymous sub that does fast-path rowobj writes whenever it's called β‘
π close
$fsdb->close;
closes the file and kills the saved writer sub. bye bestie π
π write_comment
$fsdb->write_comment($c);
writes out $c as a comment. important: $c should be just the text, with no # header in front and no newline trailer at the end, ok? πΈ
π₯ write_raw
$fsdb->write_raw($c);
writes out $c as raw output β typically because it's a comment that already has a # in front and a newline at the rear, so you don't want us doubling up on you π
π format_fsdb_fields
format_fsdb_fields(\%data, \@fields)
returns a string that's the double-space-separated, formatted version of the hash'd fields stored in %data, listed out in @fields.
real talk: this routine is a hack π there needs to be a FsdbWriter to do this properly, but there isn't one currently. so we work with what we have, periodt.
okay that's the whole page, bestie β written by the Perl gods, packaged up as perl v5.32.1 and dated 2024-08-02. mwah, go write some fsdb files ππ«Ά
π¦ where this page comes from
- epel 9: perl-Fsdb 2:3.9-1.el9 Β· GPLv2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms