Perl编译错误

  • 本文关键字:错误 编译 Perl perl
  • 更新时间 :
  • 英文 :


我似乎得到了一些编译错误,我无法弄清楚。任何帮助都将非常感激。程序的基本功能是用来管理用户列表。

我得到的错误是:

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

代码如下:

use warnings;
use lib "C:UsersmteDesktop";

 $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;

第一个问题是这一行。

use lib "C:UsersmteDesktop";

在Perl中,是转义字符。它也用于特殊字符,如n(换行符)。Perl将UmD作为特殊字符读取。虽然有一个U,但它不理解其余部分。

为了避免这种情况,您需要转义转义字符。

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

syntax error at C:UsersmteDesktoporg11.pl line 119, near "$usernames1 ("

这是由于前一行缺少分号导致Perl认为openfor循环都是一个语句。Perl不擅长检测缺失的分号;如果语法错误令人费解,检查前一行。


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

相关内容

最新更新