use strict; use Cwd; my ($path,$dir); my @textfiles; if (@ARGV) { $path = $ARGV[0]; $dir = ( $path )?$path:getcwd(); opendir DIR,$dir or die "can't read '$dir' $!\n"; @textfiles = map{ "$dir\\$_" }grep{ /\.txt$/ }readdir( DIR ); closedir DIR; } else { opendir(DIR,'.') || die "Can't read current directory: $!\n"; @textfiles = sort grep /\.txt$/i, readdir DIR; closedir DIR; } die "\n Didn't get TEXT files to validate.\n" if (@textfiles == 0); print "\nChecking the TEXT Files...."; foreach my $textfiles (@textfiles) { unless(-f $textfiles and -e $textfiles) { print "\nInvalid. Please specify valid Input text File.\n"; } print "\n\tProcessing................. $textfiles"; open IN, $textfiles || die "Can't open the '$textfiles' for initial cleanup"; { local $/; $_ = ; close IN; } my $tmp = $_; $tmp=~ s{\n{2}}{\n}gi; $tmp=~ s{([^-])--([^-])}{$1 – $2}gi; my $outfile = $textfiles; $outfile =~ s/\.txt/\.convtxt/g; $outfile =~ s/\.convtxt/\.txt/g; #open (OUT, ">Out-$ARGV[0]") or die "Cannot create the output file"; open OUT, ">$outfile" || die "Can't create the output file:'$outfile'"; print OUT $tmp; close OUT; }