Catman...er::TSV(3pm)

πŸ“¦
version 1.2025 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸŽ€ NAME πŸŽ€

ok so bestie, meet Catmandu::Exporter::TSV β€” a tab-delimited TSV exporter πŸ’– (yes it's a Catmandu::Exporter, it lives in the perl 3pm manual pages, and it's here to make tabs happen)


✨ SYNOPSIS ✨

first up, from the command line πŸ‘‡

# From the command line

# Provide a hint to the exporter which fields to export from the JSON
# input. By default the TSV exporter will export the fields that are
# found in the first JSON record.
$ catmandu convert JSON to TSV --fields "id,title,year" < data.json

and then in a Perl script, because we contain multitudes πŸ¦‹

# In a Perl script

use Catmandu;

my $exporter = Catmandu->exporter(
            'TSV',
            fix => 'myfix.txt',
            fields => "f1,f2,f3",
            header => 1);

my $exporter = Catmandu->exporter(
            'TSV',
            fields => [qw(f1 f2 f3)]);

$exporter->add_many($arrayref);
$exporter->add_many($iterator);
$exporter->add_many(sub { });

$exporter->add($hashref);

printf "exported %d items\n" , $exporter->count;

πŸ’… DESCRIPTION πŸ’…

This Catmandu::Exporter exports items as rows with tab-separated values (TSV). no cap, that's literally the whole vibe. 🧚

A header line with field names will be included if option header is set. if you wanna know how to configure the field mapping and the column names, go look at Catmandu::TabularExporter, she's the one with the answers. πŸ‘‘

Newlines and tabulator values in field values are escaped as "\n", "\r", and "\t". so no, a rogue tab in your data can't come for your columns' lives. protected. 🫢

Hint: by default, the exporter will output all the fields that are found in the first record of the data input. This can be changed by setting the fields option of the exporter. (yes this is a hint, take it, it's free)

🌸 CONFIGURATION 🌸

  • file β€” Write output to a local file given by its path or file handle. Alternatively a scalar reference can be passed to write to a string and a code reference can be used to write to a callback function. choose your fighter ✨
  • fh β€” Write the output to an IO::Handle. If not specified, Catmandu::Util::io is used to create the output handle from the "file" argument or by using STDOUT. default behaviour is giving STDOUT, iconic tbh
  • fix β€” An ARRAY of one or more fixes or file scripts to be applied to exported items. glow-up pipeline πŸ’–
  • encoding β€” Binmode of the output stream "fh". Set to ":utf8" by default. (that's ":utf8" with the quotes, she's specific like that)
  • fields β€” See Catmandu::TabularExporter. (she explains it better, iykyk)
  • columns β€” See Catmandu::TabularExporter. (same bestie, same)
  • header β€” Include a header line with column names. Enabled by default. πŸ‘‘
  • sep_char β€” Column separator ("tab" by default) β€” yes you can change it, but like... it's a TSV exporter. live your truth i guess πŸ¦‹

πŸ’œ METHODS πŸ’œ

See Catmandu::TabularExporter, Catmandu::Exporter, Catmandu::Addable, Catmandu::Fixable, Catmandu::Counter, and Catmandu::Logger for a full list of methods.

that's the whole squad fr fr β€” go read them if you want the full method menu πŸ“


🌈 SEE ALSO 🌈

  • Catmandu::Importer::TSV β€” the other half of the ship, the one that reads them back in πŸ’–

and that's the tea, bestie πŸŽ€ this page ships with perl v5.40.1, dated 2026-01-24, from the User Contributed Perl Documentation corner of the manual, filed under Catmandu::Exporter::TSV in section 3pm β€” go forth and tab-separate πŸ’…βœ¨

πŸ“¦ where this page comes from