Skip to content

Commit

Permalink
Merge pull request #231 from mknos/paste-'-'-is-stdin
Browse files Browse the repository at this point in the history
paste: '-' is stdin
  • Loading branch information
briandfoy authored Sep 8, 2023
2 parents 8121da0 + 0587e0b commit 353ddd4
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions bin/paste
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ License: perl


use strict;
no strict 'refs';

my ($VERSION) = '1.2';
use File::Basename qw(basename);

use constant EX_SUCCESS => 0;
use constant EX_FAILURE => 1;

my $Program = basename($0);
my ($VERSION) = '1.3';

my @fh;

Expand All @@ -39,13 +44,24 @@ EOF
/^-s$/ and do { $dash_ess = 1; next; }
}

if (@ARGV) {
for my $i (0..$#ARGV) {
$fh[$i] = "F$i";
open($fh[$i], '<', $ARGV[$i]) or die "$0: cannot open $ARGV[$i]";
if (scalar(@ARGV) == 0) {
@ARGV = ('-');
}
foreach my $f (@ARGV) {
if (-d $f) {
warn "$Program: '$f': is a directory\n";
exit EX_FAILURE;
}
if ($f eq '-') {
push @fh, *STDIN;
} else {
my $fil;
unless (open $fil, '<', $f) {
warn "$Program: '$f': $!\n";
exit EX_FAILURE;
}
push @fh, $fil;
}
} else {
$fh[0] = \*STDIN;
}

if ($dash_ess) {
Expand Down Expand Up @@ -105,7 +121,7 @@ paste [-s] [-d list] [file...]
=head1 DESCRIPTION
Paste combines the corresponding lines of multiple files. Each line of each
file is printed seperated by tab (or by the characters listed in the -d
file is printed separated by a tab character (or by the characters listed in the -d
option). If no files are specified, stdin is read.
=head2 OPTIONS
Expand Down Expand Up @@ -134,8 +150,7 @@ The working of I<paste> is not influenced by any environment variables.
=head1 BUGS
I<paste> has no known bugs, unless you count the use of eval EXPR. Getting
it to work under 'strict refs' would be nice, too.
I<paste> has no known bugs, unless you count the use of eval EXPR.
=head1 AUTHOR
Expand Down

0 comments on commit 353ddd4

Please sign in to comment.