| 1 | package Acme::CPANModules::WorkingWithCSV; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use Acme::CPANModulesUtil::Misc; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |
| 7 | 1 | our $DATE = '2022-12-02'; # DATE | |
| 8 | 1 | our $DIST = 'Acme-CPANModules-WorkingWithCSV'; # DIST | |
| 9 | 1 | our $VERSION = '0.002'; # VERSION | |
| 10 | |||
| 11 | 1 | my $text = <<'_'; | |
| 12 | The following are tools (modules and scripts) to work with the CSV format: | ||
| 13 | |||
| 14 | |||
| 15 | **Parsing** | ||
| 16 | |||
| 17 | First things first, the most important module to work with CSV in Perl is | ||
| 18 | <pm:Text::CSV> (which will use <pm:Text::CSV_XS> backend when possible but fall | ||
| 19 | back to <pm:Text::CSV_PP> otherwise). It's not in core, but only a cpanm command | ||
| 20 | away. | ||
| 21 | |||
| 22 | |||
| 23 | **Generating CSV from Perl array/structure** | ||
| 24 | |||
| 25 | <pm:Text::CSV> (as well as <pm:Text::CSV_XS>) can render a line of CSV from Perl | ||
| 26 | array(ref) with their `say()` method. | ||
| 27 | |||
| 28 | <prog:dd2csv> from <pm:App::CSVUtils> | ||
| 29 | |||
| 30 | <pm:Perinci::CmdLine> framework can render function result (CLI output) as CSV. | ||
| 31 | |||
| 32 | |||
| 33 | **Converting to/from other formats** | ||
| 34 | |||
| 35 | *INI*: <prog:ini2csv> from <pm:App::TextTableUtils> | ||
| 36 | |||
| 37 | *TSV*: <prog:csv2tsv> and L<prog:tsv2csv> from <pm:App::CSVUtils> | ||
| 38 | |||
| 39 | *LTSV*: <prog:csv2ltsv> from <pm:App::CSVUtils> and L<prog:ltsv2csv> from | ||
| 40 | <pm:App::LTSVUtils> | ||
| 41 | |||
| 42 | *XLS* and *XLSX*: <prog:csv2tsv> and <prog:tsv2csv> from <pm:App::CSVUtils> | ||
| 43 | |||
| 44 | *JSON*: <prog:csv2json> and <prog:json2csv> from <pm:App::TextTableUtils> | ||
| 45 | |||
| 46 | *Markdown table*: <prog:csv2mdtable> from <pm:App::TextTableUtils> | ||
| 47 | |||
| 48 | *Org table*: <prog:csv2orgtable> from <pm:App::TextTableUtils> | ||
| 49 | |||
| 50 | *SQLite database*: <prog:csv2sqlite> from <pm:App::SQLiteUtils> | ||
| 51 | |||
| 52 | |||
| 53 | **Rendering as text/ASCII table** | ||
| 54 | |||
| 55 | <prog:csv2texttable> from <pm:App::TextTableUtils> | ||
| 56 | |||
| 57 | |||
| 58 | **Changing field separator character, field quote character, and/or escape character** | ||
| 59 | |||
| 60 | <prog:csv-csv> from <pm:App::CSVUtils> | ||
| 61 | |||
| 62 | |||
| 63 | **Adding/removing columns** | ||
| 64 | |||
| 65 | <prog:csv-add-fields>, <prog:csv-delete-field>, <prog:csv-select-fields> from | ||
| 66 | <pm:App::CSVUtils> | ||
| 67 | |||
| 68 | |||
| 69 | **Processing columns of CSV with Perl code** | ||
| 70 | |||
| 71 | <prog:csv-munge-field> from <pm:App::CSVUtils> | ||
| 72 | |||
| 73 | |||
| 74 | **Processing rows of CSV with Perl code** | ||
| 75 | |||
| 76 | Aside from the obvious <pm:Text::CSV>, you can also use <prog:csv-each-row>, | ||
| 77 | <prog:csv-munge-row>, <prog:csv-mp> from <pm:App::CSVUtils>. | ||
| 78 | |||
| 79 | |||
| 80 | **Merging rows from several CSV files into one** | ||
| 81 | |||
| 82 | <prog:csv-setop>, <prog:csv-concat> from <pm:App::CSVUtils> | ||
| 83 | |||
| 84 | |||
| 85 | **Splitting a CSV file into several** | ||
| 86 | |||
| 87 | <prog:csv-split> from <pm:App::CSVUtils> | ||
| 88 | |||
| 89 | |||
| 90 | **Sorting CSV rows** | ||
| 91 | |||
| 92 | <prog:csv-sort> from <pm:App::CSVUtils> | ||
| 93 | |||
| 94 | |||
| 95 | **Sorting CSV columns** | ||
| 96 | |||
| 97 | <prog:csv-sort-fields> from <pm:App::CSVUtils> | ||
| 98 | |||
| 99 | |||
| 100 | **Filtering CSV columns** | ||
| 101 | |||
| 102 | <prog:csv-select-fields> from <pm:App::CSVUtils> | ||
| 103 | |||
| 104 | |||
| 105 | **Filtering CSV rows** | ||
| 106 | |||
| 107 | <prog:csv-grep> and <prog:csv-select-rows> from <pm:App::CSVUtils> | ||
| 108 | |||
| 109 | <prog:csvgrep> from <pm:csvgrep> | ||
| 110 | |||
| 111 | |||
| 112 | **Transposing CSV** | ||
| 113 | |||
| 114 | <prog:csv-transpose> from <pm:App::CSVUtils> | ||
| 115 | |||
| 116 | |||
| 117 | **Summing and averaging rows** | ||
| 118 | |||
| 119 | <prog:csv-sum> and <prog:csv-avg> from <pm:App::CSVUtils> | ||
| 120 | |||
| 121 | |||
| 122 | **Producing frequency table from CSV** | ||
| 123 | |||
| 124 | <prog:csv-freqtable> from <pm:App::CSVUtils> | ||
| 125 | |||
| 126 | |||
| 127 | **Performing set operations (intersection, union, difference) on CSV** | ||
| 128 | |||
| 129 | <prog:csv-setop> from <pm:App::CSVUtils> | ||
| 130 | |||
| 131 | _ | ||
| 132 | |||
| 133 | 1 | our $LIST = { | |
| 134 | summary => 'Working with CSV (comma-separated value) data in Perl', | ||
| 135 | description => $text, | ||
| 136 | tags => ['task'], | ||
| 137 | }; | ||
| 138 | |||
| 139 | 1 | Acme::CPANModulesUtil::Misc::populate_entries_from_module_links_in_description; | |
| 140 | |||
| 141 | 1 | 1; | |
| 142 | # ABSTRACT: Working with CSV (comma-separated value) data in Perl | ||
| 143 | |||
| 144 | __END__ | ||