I seem to be getting some compiling errors i cannot figure out. any help would be greatly appreciated. the basic function of the program was created to manage a list of users.
the errors i am getting are:
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.
Here is the code.
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;