Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl编译错误_Perl - Fatal编程技术网

Perl编译错误

Perl编译错误,perl,Perl,我似乎遇到了一些我无法理解的编译错误。任何帮助都将不胜感激。创建该程序的基本功能是为了管理用户列表 我得到的错误是: C:\Users\mte>perl C:\Users\mte\Desktop\org11.pl Unrecognized escape \m passed through at C:\Users\mte\Desktop\org11.pl line 2. Unrecognized escape \D passed through at C:\Users\mte\Desktop

我似乎遇到了一些我无法理解的编译错误。任何帮助都将不胜感激。创建该程序的基本功能是为了管理用户列表

我得到的错误是:

C:\Users\mte>perl C:\Users\mte\Desktop\org11.pl
Unrecognized escape \m passed through at C:\Users\mte\Desktop\org11.pl line 2.
Unrecognized escape \D passed through at C:\Users\mte\Desktop\org11.pl line 2.
Unquoted string "pm" may clash with future reserved word at C:\Users\mte\Desktop\org11.pl line 3.
syntax error at C:\Users\mte\Desktop\org11.pl line 3, near "use org22."
syntax error at C:\Users\mte\Desktop\org11.pl line 119, near "$usernames1 ("
syntax error at C:\Users\mte\Desktop\org11.pl line 126, near "}"
Execution of C:\Users\mte\Desktop\org11.pl aborted due to compilation errors.
这是代码

use warnings;
use lib "C:\Users\mte\Desktop";


 $nameoffile;  #name of file
 $filename;   #the full path of the file

 print "what is the name of the filename:", "\n";
 $nameoffile = <>;
 chomp($nameofile);

 if (-e $nameoffile)
 {
 open ($filehandle, "<", $nameoffile);
 }
 else
 {
 open ($filehandle, ">", $nameoffile);
 }

  # load user accoutns from filefield;
 %useraccountshash = ();
 %useroptionsfunction = ('i' =>\&insert_user, 'm'=>\&modify_user,                
 'r'=>\&remove_user, 'g'=>\&generate_list);


 while ($loadlines=<$filehandle>)   # load all data into hash if the file already exists
 {

 # this array temporarily holds the user data while we prepare it to go to hash

 @myarray = split(/:/, $loadlines); # split the line at the colon, will put username into index 0 in the array, and password in index 1
 $username=$myarray[0];



$password=$myarray[1];
chomp($password);

$username=~ s/[^a-zA-Z0-9]//g;
$username=lc($username);

$password=~ s/\'//g;

# now we are putting in the user name and password into the hash , array to va, variiables, variables to hash

$useraccounthash{$username} = $password; 

}

#user account interface
print "\t","\n","User Accounts","\n";
print "-------------","\n";

print "i = Insert new user account","\n";
print "m = modify existing user account","\n";
print "r = Remove existing user account","\n";
print "g = Generate list of accounts","\n";
print "q = Quit","\n","\n";

@userAccounts = ();
$userNameStorage;

#insert new user account interface

print("Enter Choice:");


while ($input != 'q')
{
while($input = <>) {
chomp $input; 

if ($input eq "i"){
 $command=$useroptionsfunction{i};
 %useraccountshash=$command->(\%useraccountshash); 


 }

 #modify username and password interface
 elsif ($input eq "m"){
 $command=$useroptionsfunction{m};
 %useraccountshash=$command->(\%useraccountshash); 

 }

 #remove the user interface
 elsif ($input eq "r"){
 $command=$useroptionsfunction{r};
 %useraccountshash=$command->(\%useraccountshash); 

 }

 #generate list of accounts 
 elsif ($input eq "g"){
 $command=$useroptionsfunction{g};
 %useraccountshash=$command->(\%useraccountshash); 

 }

 elsif ($input eq "q"){

 print "Quitting Program...";


 }
 }
 }
 close ($filehandle);
  print "save changes? type, y or n";

 $userinput=<>;
 chomp($userinput);

  if ($userinput eq 'y')
 {
 open ($filehandle, ">", $filename)

 for $usernames1 (keys %useraccounthash) 

 {  # used to iterate through the hash and pull out usernames 
  print $filehandle "$usernames1:$useraccountshash{$usernames1}\n"; #goes            
  through keys and writes the key and value to file
  }

 close ($filehandle);
 }

   1;
使用警告;
使用lib“C:\Users\mte\Desktop”;
$nameoffile#文件名
$filename#文件的完整路径
打印“文件名的名称:”,“\n”;
$nameoffile=;
chomp($nameofile);
如果(-e$nameoffile)
{
打开($filehandle,“,$nameoffile);
}
#从文件字段加载用户帐户;
%useraccountshash=();
%useroptions函数=('i'=>\&插入用户,'m'=>\&修改用户,
'r'=>\&删除用户,'g'=>\&生成用户列表);
而($loadlines=)#如果文件已经存在,则将所有数据加载到哈希中
{
#当我们准备将用户数据放入哈希时,该数组暂时保存用户数据
@myarray=split(/:/,$loadlines);#在冒号处拆分行,将用户名放入数组的索引0中,密码放入索引1中
$username=$myarray[0];
$password=$myarray[1];
chomp($password);
$username=~s/[^a-zA-Z0-9]//g;
$username=lc($username);
$password=~s/\'//g;
#现在我们将用户名和密码输入到哈希中,数组到va,变量,变量到哈希
$useraccounthash{$username}=$password;
}
#用户帐户界面
打印“\t”、“\n”、“用户帐户”、“\n”;
打印“-----------”,“\n”;
打印“i=插入新用户帐户”、“\n”;
打印“m=修改现有用户帐户”、“\n”;
打印“r=删除现有用户帐户”、“\n”;
打印“g=生成帐户列表”、“\n”;
打印“q=Quit”、“\n”、“\n”;
@用户帐户=();
$userNameStorage;
#插入新的用户帐户界面
打印(“输入选项:”);
而($input!='q')
{
而($input=){
chomp$输入;
if($input eq“i”){
$command=$useroptionsfunction{i};
%useraccountshash=$command->(\%useraccountshash);
}
#修改用户名和密码界面
elsif($input eq“m”){
$command=$useroptionsfunction{m};
%useraccountshash=$command->(\%useraccountshash);
}
#删除用户界面
elsif($input eq“r”){
$command=$useroptionsfunction{r};
%useraccountshash=$command->(\%useraccountshash);
}
#生成帐户列表
elsif($input eq“g”){
$command=$useroptionsfunction{g};
%useraccountshash=$command->(\%useraccountshash);
}
elsif($input eq“q”){
打印“退出计划…”;
}
}
}
关闭($filehandle);
打印“保存更改”类型,y或n;
$userinput=;
chomp($userinput);
if($userinput eq'y')
{
打开($filehandle,“>”,$filename)
对于$usernames1(键%useraccounthash)
{#用于迭代散列并提取用户名
打印$filehandle“$usernames1:$useraccountshash{$usernames1}\n”#
通过键并将键和值写入文件
}
关闭($filehandle);
}
1.

第一个问题是这条线

use lib "C:\Users\mte\Desktop";
在Perl中,
\
是转义字符。它还用于特殊字符,如
\n
(换行符)。Perl将
\U
\m
\D
读取为特殊字符。虽然有一个
\U
,但它不理解其余部分

要避免这种情况,需要转义转义字符

use lib "C:\\Users\\mte\\Desktop";

这是因为前一行中缺少分号,导致Perl认为
open
for
循环都是一条语句。Perl不擅长检测缺失的分号;如果语法错误令人费解,请检查前一行



其余的错误消息是指您没有发布的代码。

我看到您发现了警告。如果您想要,它将为您节省数小时令人沮丧的调试时间。您还需要缩进代码。当您在行首点击
tab
时,大多数人都会为您这样做。您还可以使用开始。最后,将为您查找文件错误。它理解
\U
很好,只是与提问者的理解不一致。:)当OP有一个没有插值的简单文本字符串时,为什么建议“转义字符”?在我看来,单引号,ala
使用lib'C:\Users\mte\Desktop'
是一种更好的鼓励实践。您是否出于教学原因建议在本例中使用转义?@type_outcast I总是忘了\不会插入单引号(除了\')。我倾向于发垃圾邮件
四处走动。让我修改一个教学理由。。。最后,他们会希望插入一个Windows路径。此外,如果你愿意的话,我敢肯定perl会很乐意使用/,而不是-,来处理Windows路径。@Joshua简单的文件名可能是安全的。Perl正在向Windows API提供路径,Windows API几乎总是接受/。Windows程序也可能会工作。有关更多详细信息,请参阅。
syntax error at C:\Users\mte\Desktop\org11.pl line 119, near "$usernames1 ("