Catmandu::Importer::Text(3) Package that imports textual data


With catmandu command line client:

# separate fields by whitespace sequences just like awk
catmandu convert Text --split '\s+'
# import all lines starting with '#', omitting this character
catmandu convert Text --pattern '^#(.*)'

In Perl code:

    use Catmandu::Importer::Text;
    my $importer = Catmandu::Importer::text->new( file => "/foo/bar.txt" );
    # print all lines with line number
    $importer->each(sub {
        my $item = $_[0];
        printf "%d: %s" , $item->{_id} , $item->{text};  


This Catmandu::Importer reads each line of input as an item with line number in field "_id" and text content in field "text". Line separators are not included. A regular expression can be specified to only import selected lines and parts of lines that match a given pattern.


Read input from a local file given by its path. Alternatively a scalar reference can be passed to read from a string.
Read input from an IO::Handle. If not specified, Catmandu::Util::io is used to create the input stream from the "file" argument or by using STDIN.
Binmode of the input stream "fh". Set to ":utf8" by default.
An ARRAY of one or more fixes or file scripts to be applied to imported items.
Character or regular expression (given as string with a least two characters), to split each line. Resulting parts are imported in field "text" as array.
Regular expression, given as string, to only import matching lines. Whitespaces in patterns are ignored or must be escaped if patterns consists of multiple lines. If the pattern contains capturing groups, captured values are imported in field "match" instead of "text".

For instance dates in "YYYY-MM-DD" format can be imported as named fields with


or as array with

   (\d\d\d\d)-  # year
   (\d\d)-      # month
   (\d\d)       # day


Every Catmandu::Importer is a Catmandu::Iterable all its methods are inherited.