App-CSVUtils
view release on metacpan or search on metacpan
script/csv-fill-cells view on Meta::CPAN
This utility takes values (from cells of a 1-column input CSV), creates an
output CSV of specified size, and fills the output CSV in one of several
possible ways ("layouts"): left-to-right first then top-to-bottom, or
bottom-to-top then left-to-right, etc.
Some illustration of the layout:
% cat 1-to-100.csv
num
1
2
3
...
100
% csv-fill-cells 1-to-100.csv --num-rows 10 --num-fields 10 ; # default layout is 'left_to_right_then_top_to_bottom'
field0,field1,field2,field3,field4,field5,field6,field7,field8,field9
1,2,3,4,5,6,7,8,9,10
11,12,13,14,15,16,17,18,19,20
21,22,23,24,25,26,27,28,29,30
...
91,92,93,94,95,96,97,98,99,100
% csv-fill-cells 1-to-100.csv --num-rows 10 --num-fields 10 --layout top_to_bottom_then_left_to_right
field0,field1,field2,field3,field4,field5,field6,field7,field8,field9
1,11,21,31,41,51,61,71,81,91
2,12,22,32,42,52,62,72,82,92
3,13,23,33,43,53,63,73,83,93
...
10,20,30,40,50,60,70,80,90,100
% csv-fill-cells 1-to-100.csv --num-rows 10 --num-fields 10 --layout top_to_bottom_then_right_to_left
91,81,71,61,51,41,31,21,11,1
92,82,72,62,52,42,32,22,12,2
93,83,73,63,53,43,33,23,13,3
...
100,90,80,70,60,50,40,30,20,10
% csv-fill-cells 1-to-100.csv --num-rows 10 --num-fields 10 --layout right_to_left_then_top_to_bottom
10,9,8,7,6,5,4,3,2,1
20,19,18,17,16,15,14,13,12,11
30,29,28,27,26,25,24,23,22,21
...
100,99,98,97,96,95,94,93,92,91
Some additional options are available, e.g.: a filter to let skip filling some
cells.
When there are more input values than can be fitted, the extra input values are
not placed into the output CSV.
When there are less input values to fill the specified number of rows, then only
the required number of rows and/or columns will be used.
Additional options planned:
=over
=item * what to do when there are less values to completely fill the output CSV
(whether to always expand or expand when necessary, which is the default).
=item * what to do when there are more values (extend the table or ignore the extra
input values, which is the default).
=back
=head1 OPTIONS
C<*> marks required options.
=head2 Filtering options
=over
=item B<--filter>=I<s>
Code to filter cells to fill.
Code will be compiled in the C<main> package.
Code is passed C<($r, $output_row_num, $output_field_idx)> where C<$r> is the
stash, C<$output_row_num> is a 1-based integer (first data row means 1), and
C<$output_field_idx> is the 0-based field index (0 means the first index). Code
is expected to return a boolean value, where true meaning the cell should be
filied.
=back
=head2 Input options
=over
=item B<--input-escape-char>=I<s>
Specify character to escape value in field in input CSV, will be passed to Text::CSV_XS.
Defaults to C<\\> (backslash). Overrides C<--input-tsv> option.
=item B<--input-filename>=I<s>
Input CSV file.
Default value:
"-"
Use C<-> to read from stdin.
Encoding of input file is assumed to be UTF-8.
Can also be specified as the 1st command-line argument.
=item B<--input-quote-char>=I<s>
Specify field quote character in input CSV, will be passed to Text::CSV_XS.
Defaults to C<"> (double quote). Overrides C<--input-tsv> option.
( run in 1.484 second using v1.01-cache-2.11-cpan-a9496e3eb41 )