I need a Perl script on Windows which deletes the newline characters from a file and merges all the lines into one line and then writes into another file into the %temp% directory on a Windows system. For example, this script is to delete newlines and create a single line and write into another file in %TEMP%.
I have script which deletes the newlines but the output goes to STDOUT. I am not able to create a file in %TEMP% and redirect the output to that file.
Following is my script which is not working:
my $inFile = $ARGV[0];
$ENV{'TEMP'} = 'C:\\TEMP';
if ($inFile eq "") {
print "Input file is missing\n";
print "perl file_into_one_line.pl <input fil>\n";
exit 0;
}
open(INFILE, "< $inFile") || die "$0, FEJL: can't open $inFile: $!";
foreach (<INFILE>) {
chomp;
if (eof()) { # check for end of last file
print "$_\n";
} else {
open FILE, ">$ENV{'TEMP'}//temp//tst.txt" or die;
print FILE "${_}$separator";
}
}
close(INFILE);
perl myscript.pl >%TEMP%/file.txtinFilecan beundef, so check!defined $inFile || $inFile eq "".