Catmandu::Importer::Text(3pm) | User Contributed Perl Documentation | Catmandu::Importer::Text(3pm) |
Catmandu::Importer::Text - Package that imports textual data
# From the command line # 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 a Perl script use Catmandu; my $importer = Catmandu->importer('Text' , file => "/foo/bar.txt" ); # print all lines with line number $importer->each(sub { my $item = $_[0]; printf "%d: %s" , $item->{_id} , $item->{text}; });
This package reads textual input line by line. Each line is imported as item with line number in field "_id" and text content in field "text". Line separators are not included. Lines can further be split by character or pattern and a regular expression can be specified to only import selected lines and to translate pattern groups to fields.
For instance dates in "YYYY-MM-DD" format can be imported as named fields with
(?<year>\d\d\d\d)-(?<month>\d\d)-(?<day>\d\d)
or as array with
(\d\d\d\d)- # year (\d\d)- # month (\d\d) # day
Every Catmandu::Importer is a Catmandu::Iterable with all its methods inherited.
Catmandu::Exporter::Text
Catmandu::Fix::parse_text
Unix tools awk <https://en.wikipedia.org/wiki/AWK> and sed <https://en.wikipedia.org/wiki/Sed>
2023-03-03 | perl v5.36.0 |