[clug] Thursday afternoon Perl/bash golf time

Tony Breeds tony at bakeyournoodle.com
Thu Jun 11 16:04:45 MDT 2015


On Thu, Jun 11, 2015 at 08:02:46PM +1000, Andrew Janke wrote:
> 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.

But you said 'perl golf' Not 'help me write useful perl ;P
http://www.perlmonks.org/?node_id=551876

Yours Tony.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/linux/attachments/20150612/dbd34043/attachment.pgp>


More information about the linux mailing list