App-TSVUtils
view release on metacpan or search on metacpan
lib/App/TSVUtils.pm view on Meta::CPAN
);
my %arg_filename_0 = (
filename => {
summary => 'Input TSV file',
schema => 'filename*',
req => 1,
pos => 0,
cmdline_aliases => {f=>{}},
},
);
my %arg_filename_1 = (
filename => {
summary => 'Input TSV file',
description => <<'_',
Use `-` to read from stdin.
_
schema => 'filename*',
req => 1,
pos => 1,
cmdline_aliases => {f=>{}},
},
);
$SPEC{tsvutil} = {
v => 1.1,
summary => 'Perform action on a TSV file',
'x.no_index' => 1,
args => {
%args_common,
action => {
schema => ['str*', in=>[
'dump',
]],
req => 1,
pos => 0,
cmdline_aliases => {a=>{}},
},
%arg_filename_1,
},
args_rels => {
},
};
sub tsvutil {
my %args = @_;
my $action = $args{action};
my $res = "";
my $i = 0;
my $fh;
if ($args{filename} eq '-') {
$fh = *STDIN;
} else {
open $fh, "<", $args{filename} or
return [500, "Can't open input filename '$args{filename}': $!"];
}
binmode $fh, ":encoding(utf8)";
;
my $code_getline = sub {
my $row0 = <$fh>;
return undef unless defined $row0;
chomp($row0);
[split /\t/, $row0];
};
my $rows = [];
while (my $row = $code_getline->()) {
$i++;
if ($action eq 'dump') {
push @$rows, $row;
} else {
return [400, "Unknown action '$action'"];
}
} # while getline()
if ($action eq 'dump') {
return [200, "OK", $rows];
}
[200, "OK", $res, {"cmdline.skip_format"=>1}];
} # tsvutil
$SPEC{tsv_dump} = {
v => 1.1,
summary => 'Dump TSV as data structure (array of arrays)',
args => {
%args_common,
%arg_filename_0,
},
};
sub tsv_dump {
my %args = @_;
tsvutil(%args, action=>'dump');
}
1;
# ABSTRACT: CLI utilities related to TSV
__END__
=pod
=encoding UTF-8
=head1 NAME
App::TSVUtils - CLI utilities related to TSV
=head1 VERSION
This document describes version 0.004 of App::TSVUtils (from Perl distribution App-TSVUtils), released on 2019-12-19.
=head1 DESCRIPTION
This distribution contains the following CLI utilities:
( run in 1.500 second using v1.01-cache-2.11-cpan-140bd7fdf52 )