[clug] Thursday afternoon Perl/bash golf time

Andrew Janke a.janke at gmail.com
Thu Jun 11 04:02:46 MDT 2015


On 11 June 2015 at 16:51, Peter Barker <pbarker at barker.dropbear.id.au> wrote:
> Good idea!
>
>
> #!/usr/bin/perl -w
>
> use strict;
> use warnings;
>
> use Fcntl qw (O_WRONLY O_CREAT O_TRUNC );
> use FileHandle qw ();
>
> sub catfiles {
>   my ($out_filepath, $files) = @_;
>   my $out = FileHandle->new($out_filepath, O_WRONLY|O_CREAT|O_TRUNC) or die
> "Crud: $!";
>   foreach my $file (@$files) {
>     my $stuff;
>     my $in = FileHandle->new($file) or die "Crud ($file): $!";
>     while (sysread($in,$stuff,16384)) {
>       syswrite($out,$stuff,16384) or die "Failed to write: $!";
>     }
>   }
>   $out->close() or die "Failed to close ($out_filepath): $!";
> }
>
> my $out = "/tmp/way-too-big.txt";
> my @files = ('/etc/passwd','/etc/group');
> &catfiles($out, \@files);

Thanks

I've used something close to this.

a


More information about the linux mailing list