App-CSVUtils
view release on metacpan or search on metacpan
lib/App/CSVUtils/csv_concat.pm view on Meta::CPAN
}
}
my $csv = $r->{input_parser};
if ($r->{util_args}{overlay}) {
my $overwrite_fields = $r->{util_args}{overwrite_fields};
my $output_fields_idx = $r->{output_fields_idx};
while (1) {
my $has_not_eof;
my $combined_row = [("") x @{ $r->{output_fields} }];
my %seen_fields;
for my $i (0 .. $#{ $r->{all_input_fh} }) {
my $fh = $r->{all_input_fh}[$i];
next if eof($fh);
$has_not_eof++;
my $row = $csv->getline($fh);
my $input_fields = $r->{all_input_fields}[$i];
for my $j (0 .. $#{ $input_fields }) {
my $field = $input_fields->[$j];
if (!($seen_fields{$field}++) || $overwrite_fields) {
$combined_row->[ $output_fields_idx->{$field} ] = $row->[$j];
}
}
} # for all_input_fh
last unless $has_not_eof;
$r->{code_print_row}->($combined_row);
} # while 1
} else {
# print all the data rows
for my $i (0 .. $#{ $r->{all_input_fh} }) {
log_trace "[%d/%d] Adding rows from file #%d ...",
$i+1, scalar(@{$r->{all_input_fh}}), $i+1;
my $fh = $r->{all_input_fh}[$i];
lib/App/CSVUtils/csv_find_values.pm view on Meta::CPAN
Check whether specified values are found in the `sku` field, print message when
they are (search case-insensitively):
% csv-find-values product.csv sku sku1 sk3b sku15 -i
'sku1' is found in field 'sku' row 2
'sk3b' is found in field 'sku' row 4
Print message when values are *not* found instead:
% csv-find-values product.csv sku sku1 sk3b sku15 -i --print-when=not_found
'sku15' is NOT found in field 'sku'
Always print message:
% csv-find-values product.csv sku sku1 sk3b sku15 -i --print-when=always
'sku1' is found in field 'sku' row 2
'sk3b' is found in field 'sku' row 4
'sku15' is NOT found in field 'sku'
Do custom action with Perl code, code will receive `$_` (the value being
lib/App/CSVUtils/csv_find_values.pm view on Meta::CPAN
values => {
'x.name.is_plural' => 1,
'x.name.singular' => 'value',
schema => ['array*', of=>'str*', min_len=>1],
req => 1,
pos => 2,
slurpy => 1,
},
print_when => {
schema => ['str*', in=>[qw/found not_found always/]],
default => 'found',
description => <<'_',
Overriden by the `--eval` option.
_
tags => ['category:output'],
},
%App::CSVUtils::argspecopt_eval,
},
lib/App/CSVUtils/csv_find_values.pm view on Meta::CPAN
local $main::r = $r;
local $main::csv = $r->{input_parser};
$r->{code}->($_);
}
} else {
if (defined $found_rownum) {
if ($r->{util_args}{print_when} eq 'found' || $r->{util_args}{print_when} eq 'always') {
print "'$value' is found in field '$r->{field}' row ".($found_rownum+1)."\n";
}
} else {
if ($r->{util_args}{print_when} eq 'not_found' || $r->{util_args}{print_when} eq 'always') {
print "'$value' is NOT found in field '$r->{field}'".($suggested_values && @$suggested_values ? ", perhaps you meant ".join("/", @$suggested_values)."?" : "")."\n";
}
}
}
}
},
);
1;
# ABSTRACT: Find specified values in a CSV field
lib/App/CSVUtils/csv_find_values.pm view on Meta::CPAN
Check whether specified values are found in the C<sku> field, print message when
they are (search case-insensitively):
% csv-find-values product.csv sku sku1 sk3b sku15 -i
'sku1' is found in field 'sku' row 2
'sk3b' is found in field 'sku' row 4
Print message when values are I<not> found instead:
% csv-find-values product.csv sku sku1 sk3b sku15 -i --print-when=not_found
'sku15' is NOT found in field 'sku'
Always print message:
% csv-find-values product.csv sku sku1 sk3b sku15 -i --print-when=always
'sku1' is found in field 'sku' row 2
'sk3b' is found in field 'sku' row 4
'sku15' is NOT found in field 'sku'
Do custom action with Perl code, code will receive C<$_> (the value being
script/csv-find-values view on Meta::CPAN
Check whether specified values are found in the C<sku> field, print message when
they are (search case-insensitively):
% csv-find-values product.csv sku sku1 sk3b sku15 -i
'sku1' is found in field 'sku' row 2
'sk3b' is found in field 'sku' row 4
Print message when values are I<not> found instead:
% csv-find-values product.csv sku sku1 sk3b sku15 -i --print-when=not_found
'sku15' is NOT found in field 'sku'
Always print message:
% csv-find-values product.csv sku sku1 sk3b sku15 -i --print-when=always
'sku1' is found in field 'sku' row 2
'sk3b' is found in field 'sku' row 4
'sku15' is NOT found in field 'sku'
Do custom action with Perl code, code will receive C<$_> (the value being
script/csv-find-values view on Meta::CPAN
=item B<--print-when>=I<s>
Default value:
"found"
Valid values:
["found","not_found","always"]
Overriden by the C<--eval> option.
=item B<--view-result>
View output using a viewer.
This option will first save the output to a temporary file, then open a viewer
program to view the temporary file. If a viewer program is not chosen, a
( run in 0.504 second using v1.01-cache-2.11-cpan-4d4bc49f3ae )