sub work_n_save {
... ## whatever
my $filename = $File::Find::name if !-d; ## get file name if not
+ directory
$filename = basename($filename); ## get the file base na
+me
## The line below assumes, files have extention
$filename =~ s/\..+$//; ## remove the file exte
+ntion
open my $fh_new, '>', $filename . "_Result" or croak "can't open f
+ile: $!";
open my $fh, '<', $_ or croak "can't open file: $!";
while ( defined( my $line = <$fh> ) ) {
chomp $line;
## do whatever you want
print {$fh_new} $line, $/;
}
}
NOTE:Please, don't forget that the subroutine "work_n_save" is called as sub. reference in the find subroutine of the module File::Find, which transverse the whole of the directory ( or directories).
Also, note the way the new files are opened:
open my $fh_new, '>', $filename . "_Result" or croak "can't open file:
+ $!";
Hope this helps.
|