my $upload_dir = "some directory";
my $evtFileName = 'testDoc';
my $empFileName = $query->param('filepath');
my $fh = upload('filepath');
$fh =~ s/(?=\n)/\r/g;
open OUTFILE, ">".$upload_dir."\\".$empFileName or die "Cannot open file ".$upload_dir."\\".$empFileName;
while (<$fh>)
{
print OUTFILE;
print;
}
close OUTFILE;
Indeed binmode with the appropriate layer (see PerlIO) or even directly specifying it in open's mode string may well be the best way to go.
I'd also recommend reading this thread in which a similar issue is discussed at length.
You didn't specify on which system the script is running.
If you're running on Windows, you need to remove $fh =~ s/(?=\n)/\r/g; or add [doc://binmode|binmode(OUTFILE);]. print will automatically convert \n to \r\n when binmode isn't used.
If you're running on unix and the file is in unix format as you claim, it should work as is.
If you're running on unix and the file is in dos format, you need to replace $fh =~ s/(?=\n)/\r/g; with $fh =~ s/\r//g;.
perlmonks.org content © perlmonks.org and blazar, chas, ikegami, master_son
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03