in reply to Text merge concept in perl
See Path::Tiny, File::Find::Rule
#!/usr/bin/perl -- use strict; use warnings; use Path::Tiny qw/ path /; use File::Find::Rule qw/ find /; Main( @ARGV ); exit( 0 ); sub Main { #~ MainReaddir( @_ ); MainRule( @_ ); } sub MainRule { my( $dir , $mergeinto ) = @_; my $mergefh = path( $mergeinto )->opena_utf8; my $readdir = path( $dir )->realpath; my @entries = find( file => maxdepth => 1, name => qr/\.txt$/, in => $readdir, ); for my $name ( @entries ){ my $entry = path( $name ); if( $entry->is_file and $name =~ /\.txt$/ ){ my $inputfh = $entry->openr_utf8; Mergerations( $mergefh, $inputfh ); close $inputfh; } } close $mergefh; } sub MainReaddir { my( $dir , $mergeinto ) = @_; my $mergefh = path( $mergeinto )->opena_utf8; my $readdir = path( $dir )->realpath ->iterator( { qw/ recurse 0 / }); while( my $entry = $readdir->() ){ if( $entry->is_file and $entry =~ /\.txt$/ ){ my $inputfh = path( $entry )->openr_utf8; Mergerations( $mergefh, $inputfh ); close $inputfh; } } } sub Staterator { my( $out, $in ) = @_; ... } __END__
see perlintro, also chromatics free book Modern Perl a loose description of how experienced and effective Perl 5 programmers work....You can learn this too.
Learn Perl in about 2 hours 30 minutes
|
|---|