App-CSVUtils
view release on metacpan or search on metacpan
lib/App/CSVUtils.pm view on Meta::CPAN
my ($fh, $err);
if ($filename eq '-') {
$fh = *STDIN;
} else {
open $fh, "<", $filename or do {
$err = [500, "Can't open input filename '$filename': $!"];
goto RETURN;
};
}
binmode $fh, ":encoding(utf8)";
RETURN:
($fh, $err);
}
sub _open_file_write {
my $filename = shift;
my ($fh, $err);
if ($filename eq '-') {
$fh = *STDOUT;
} else {
open $fh, ">", $filename or do {
$err = [500, "Can't open output filename '$filename': $!"];
goto RETURN;
};
}
binmode $fh, ":encoding(utf8)";
RETURN:
($fh, $err);
}
sub _return_or_write_file {
my ($res, $filename, $overwrite) = @_;
return $res if !defined($filename);
my $fh;
lib/App/CSVUtils.pm view on Meta::CPAN
if (-f $filename) {
if ($overwrite) {
log_info "[csvutil] Overwriting output file $filename";
} else {
return [412, "Refusing to ovewrite existing output file '$filename', please select another path or specify --overwrite"];
}
}
open my $fh, ">", $filename or do {
return [500, "Can't open output file '$filename': $!"];
};
binmode $fh, ":encoding(utf8)";
print $fh $res->[2];
close $fh or warn "Can't write to '$filename': $!";
return [$res->[0], $res->[1]];
}
}
sub compile_eval_code {
return $_[0] if ref $_[0] eq 'CODE';
my ($str, $label) = @_;
defined($str) && length($str) or die [400, "Please specify code ($label)"];
script/csv2ltsv view on Meta::CPAN
use warnings;
use Getopt::Long qw(:config gnu_getopt no_ignore_case);
use Text::CSV_XS;
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2025-02-04'; # DATE
our $DIST = 'App-CSVUtils'; # DIST
our $VERSION = '1.036'; # VERSION
binmode STDIN, ':encoding(utf8)';
binmode STDOUT, ':encoding(utf8)';
my %Opt = (
header => 1,
);
GetOptions(
'no-header' => sub { $Opt{header} = 0 },
);
my $csv = Text::CSV_XS->new({binary=>1});
my $i = 0;
script/csv2tsv view on Meta::CPAN
use strict;
use warnings;
use Text::CSV_XS;
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2025-02-04'; # DATE
our $DIST = 'App-CSVUtils'; # DIST
our $VERSION = '1.036'; # VERSION
binmode STDIN, ':encoding(utf8)';
binmode STDOUT, ':encoding(utf8)';
my $csv = Text::CSV_XS->new({binary=>1});
while (my $row = $csv->getline(\*ARGV)) {
print join("\t", @$row), "\n";
}
# ABSTRACT: Convert CSV to TSV
# PODNAME: csv2tsv
__END__
script/tsv2csv view on Meta::CPAN
use warnings;
use Text::CSV_XS;
use Text::CSV_XS::TSV;
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2025-02-04'; # DATE
our $DIST = 'App-CSVUtils'; # DIST
our $VERSION = '1.036'; # VERSION
binmode STDIN, ':encoding(utf8)';
binmode STDOUT, ':encoding(utf8)';
my $csv = Text::CSV_XS->new({binary=>1});
my $tsv = Text::CSV_XS::TSV->new({binary=>1});
while (my $row = $tsv->getline(\*ARGV)) {
$csv->combine(@$row);
print $csv->string, "\n";
}
# ABSTRACT: Convert TSV to CSV
t/00-compile.t view on Meta::CPAN
for my $lib (@module_files)
{
# see L<perlfaq8/How can I capture STDERR from an external command?>
my $stderr = IO::Handle->new;
diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
$^X, @switches, '-e', "require q[$lib]"))
if $ENV{PERL_COMPILE_TEST_DEBUG};
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
binmode $stderr, ':crlf' if $^O eq 'MSWin32';
my @_warnings = <$stderr>;
waitpid($pid, 0);
is($?, 0, "$lib loaded ok");
shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
and not eval { +require blib; blib->VERSION('1.01') };
if (@_warnings)
{
warn @_warnings;
t/00-compile.t view on Meta::CPAN
close $fh and skip("$file uses -T; not testable with PERL5LIB", 1)
if grep { $_ eq '-T' } @switches and $ENV{PERL5LIB};
my $stderr = IO::Handle->new;
diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
$^X, @switches, '-c', $file))
if $ENV{PERL_COMPILE_TEST_DEBUG};
my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-c', $file);
binmode $stderr, ':crlf' if $^O eq 'MSWin32';
my @_warnings = <$stderr>;
waitpid($pid, 0);
is($?, 0, "$file compiled ok");
shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
and not eval { +require blib; blib->VERSION('1.01') };
# in older perls, -c output is simply the file portion of the path being tested
if (@_warnings = grep { !/\bsyntax OK$/ }
grep { chomp; $_ ne (File::Spec->splitpath($file))[2] } @_warnings)
( run in 0.275 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )