in reply to very basic, just beginning
#!/usr/bin/perl use warnings; use strict; # open current dir, and read in all files # matching /^a\d+\.txt/ into the array @files: # opendir my $dir_handle, "." or die "can't open dir"; my @files = grep { /^a\d+\.txt/ } readdir $dir_handle; closedir $dir_handle; # For each of the files: # foreach my $filename ( @files ) { # open the file, and read its contents into the # array @file_contents, then close the file: # open my $fh, "$filename" or die "can't open $filename to read"; my @file_contents = <$fh>; close $fh; # now reopen the file (for writing), and write your # desired output to it: # open $fh, ">$filename" or die "can't open $filename to write"; print $fh ">$filename\n@file_contents\n"; close $fh; }
|
|---|