对Perl很新颖。在Padre和Windows 10 OS上运行Perl。perl新手,需要处理文件脚本的帮助
我书中的脚本是为Unix编写的。我不知道如何纠正它,以便它可以与Windows一起使用。
这是写在我的书(FOR UNIX)脚本:
use warnings;
#write to a file with a filehandle. Sriptname: file.handle
my $file="/home/jody/ellie/perl/newfile";
open(my $fh, ">", $file) || die "Can't open newfile: $!\n";
print $fh "hello world.\n";
print $fh "hello world again.\n";
在命令行
$perl file.handle
$cat newfile
输出应该看起来像这样:
hello world.
hello world again.
我做了如下修改但没有成功
use warnings;
#Write to a file with a filehandle. Scriptname: file.handle
my $file='C:\newfile.txt';
open (my $fh, ">", $file) || die "Can't open newfile: $!\n";
print $fh "hello world.\n";
print $fh "hello world again.\n";
当我运行脚本,我得到以下的输出:
can't open newfile: permission denied**
当我与调试运行脚本,我得到了以下信息:
uncaught exception for user code
can't open newfile: permission denied
at handlingfiles.pl line 5
press any key to continue
我到底做错了什么?
您的用户是否有权写入'C:\'文件夹? – choroba