in reply to parse multiple text files keep unique lines only

#!/usr/bin/perl # http://perlmonks.org/?node_id=1193719 use strict; use warnings; use File::Find; use File::Slurp qw( edit_file_lines ); my $directory = 'some/test/'; find sub { my %u; -f and /\.txt$/ and edit_file_lines sub { $_ x= !$u{$_}++ }, $_ }, $directory;

hehehe

Replies are listed 'Best First'.
Re^2: parse multiple text files keep unique lines only
by 1nickt (Canon) on Jun 28, 2017 at 08:02 UTC

    Don't use File::Slurp, it's broken.


    The way forward always starts with a minimal test.
      #!/usr/bin/perl # http://perlmonks.org/?node_id=1193719 use strict; use warnings; use File::Find; use Path::Tiny; my $directory = 'some/test/'; find sub { my %u; -f and /\.txt$/ and path($_)->edit_lines( sub { $_ x= !$u{$_}++ } ) }, $directory;

        With Path::Tiny, you don't need File::Find.

        #!/usr/bin/perl # http://perlmonks.org/?node_id=1193719 use strict; use warnings; use Path::Tiny; my $directory = 'some/test/'; path($directory)->visit ( sub { my %u; -f and /\.txt$/ and $_->edit_lines ( sub { $_ x= !$u{$_}++ } ) } );