Fsdb::IO::Writer(3)

πŸ“¦
version 3.9 Β· 3 versions
, in epel 9

πŸŽ€ 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 -file and -header too πŸ‘€
  • -file FILENAME β€” opens and writes to the filename you give it. The special filename - means standard output, and any files with hdfs: 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 like delay), 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