in reply to Reading Multiple files
If I may give you a head up. There are several ways to achieving your aim and this is one of them.
NOTE: That the script above will save the new file generated within the same directory, where the original files are.use warnings; use strict; use File::Find qw(find); use File::Basename qw(basename); use Carp qw(croak); croak "Usage: perlscript.pl <drectory_name>" unless defined $ARGV[0]; my $directory_name = $ARGV[0]; find( \&work_n_save, $directory_name ); # transverse the directory for + each file sub work_n_save { return if $_ eq '.' or $_ eq '..'; my $filename = $File::Find::name if !-d; ## get file name if not + directory $filename = basename($filename); ## get the file base na +me $filename =~ s/\..+$//; ## remove the file exte +ntion open my $fh_new, '>', $filename . "_new.txt" or croak "can't open +file: $!"; open my $fh, '<', $_ or croak "can't open file: $!"; while ( defined( my $line = <$fh> ) ) { chomp $line; ## do whatever you want print {$fh_new} $line, $/; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reading Multiple files
by maheshkumar (Sexton) on Aug 07, 2012 at 16:21 UTC | |
by 2teez (Vicar) on Aug 07, 2012 at 18:13 UTC | |
by maheshkumar (Sexton) on Aug 08, 2012 at 15:36 UTC | |
by 2teez (Vicar) on Aug 08, 2012 at 16:39 UTC |