I made the changes as you guys instructed and made some changes of my own, now I encounter an unusual error.
Welcome, Main Menu
1. Log in
2. Log out
3. Administration
Enter selection: 3
Administrative Tools
1. Add user
2. Remove user
Enter selection: 1
Enter new user name: ggamber
Enter password for ggamber: 9898
User added.
Welcome, Main Menu
1. Log in
2. Log out
3. Administration
Enter selection: 1
Enter your user name to log in: ggamber
Enter your password: 9898
Use of uninitialized value $username in hash element at ./agts-cli.pl line 39, <STDIN> line 7.
Use of uninitialized value in string eq at ./agts-cli.pl line 39, <STDIN> line 7.
Incorrect password!
New code:
#!/usr/bin/perl # # AGTS-CLI(Andrew's GTK Time System-Command Line version) # Copyright (C) 2008 Andrew Harris # # This program is free software: you can redistribute it and/or mod +ify # it under the terms of the GNU General Public License as published + by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, email andrew2325@gmail.com! # Contributors: Kelly Royal <netdaemon862@gmail.com> use strict; use warnings; my $time = localtime; my %logins = ("aharris" => "1234", "kroyal" => "5678"); sub verify { my $username = shift; if (exists $logins{$username}) { login($username, %logins); } else { print "$username does not exist in our database.\n"; } } sub login { my %logins; my $username; print "Enter your password: "; chomp(my $pass = <STDIN>); if ($pass eq $logins{$username}) { greeting($username); } else { print "Incorrect password!\n"; } } sub greeting { my $username = shift; print "Welcome $username.\n"; print "Current time is $time\n\n\n"; } sub admin { print "Administrative Tools\n"; print "1. Add user\n"; print "2. Remove user\n"; print "Enter selection: "; chomp(my $selection = <STDIN>); if ($selection == 1) { print "Enter new user name: "; chomp(my $newname = <STDIN>); print "Enter password for $newname: "; chomp(my $newpass = <STDIN>); $logins{$newname} = $newpass; print "User added.\n"; } } while (1) { print "Welcome, Main Menu\n"; print "1. Log in\n"; print "2. Log out\n"; print "3. Administration\n"; print "Enter selection: "; my $selection = <STDIN>; if ($selection == 1) { print "Enter your user name to log in: "; chomp(my $username = <STDIN>); verify($username); open(MYLOGINFILE, ">>login.txt"); print MYLOGINFILE "$username:$time\n"; close(MYLOGINFILE); } elsif ($selection == 2) { print "Enter your user name to log out: "; chomp(my $username = <STDIN>); verify($username); open(MYLOGOUTFILE, ">>login.txt"); print MYLOGOUTFILE "$username:$time\n"; close(MYLOGOUTFILE); } elsif ($selection == 3) { admin; } }

In reply to Re: adding to hash/writing to file errors by andrew2325
in thread adding to hash/writing to file errors by andrew2325

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.