| 1 | #!perl | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||
| 7 | 2 | our $DATE = '2023-02-15'; # DATE | |||||||||
| 8 | 2 | our $DIST = 'App-sponge'; # DIST | |||||||||
| 9 | 2 | our $VERSION = '0.003'; # VERSION | |||||||||
| 10 | |||||||||||
| 11 | 2 | ▶ | use Fcntl qw(:DEFAULT); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 2 | ▶ | use Getopt::Std; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 2 | my %opts; | |||||||||
| 15 | 2 | ▶ | getopts('a', \%opts) or die "sponge: Error in options processing, bailing\n"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | |||||||||||
| 17 | # soak input first | ||||||||||
| 18 | 2 | my $input; { local $/; $input = <STDIN> } | |||||||||
| 19 | |||||||||||
| 20 | 2 | ▶ | if (@ARGV) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 2 | my $fh; | |||||||||
| 22 | 2 | ▶ | if ($opts{a}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 1 | sysopen $fh, $ARGV[0], O_CREAT|O_WRONLY; | |||||||||
| 24 | 1 | seek $fh, 0, 2; | |||||||||
| 25 | } else { | ||||||||||
| 26 | 1 | sysopen $fh, $ARGV[0], O_CREAT|O_TRUNC|O_WRONLY; | |||||||||
| 27 | } | ||||||||||
| 28 | 2 | print $fh $input; | |||||||||
| 29 | } else { | ||||||||||
| 30 | # print to stdout | ||||||||||
| 31 | 0 | print $input; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | # ABSTRACT: Soak up standard input and write to a file (perl implementation) | ||||||||||
| 35 | # PODNAME: sponge | ||||||||||
| 36 | |||||||||||
| 37 | __END__ | ||||||||||