jaffinito34 has asked for the wisdom of the Perl Monks concerning the following question:
My script checks the username and password entered to that of a passwd file. If anything is incorrect the program dies. If they match, another file gets opened so that the user can see their info in the file. However, the file is split up by pipes (|) so when I use a while loop to split the file, the variables do not get properly assigned. Here's the code, the problem is the while loop at the bottom:
#! /usr/bin/perl # CSC 310 Project # 3 #opening passwd file open (PSWD, '<', 'passwd.txt'); #getting username and password #converting username to lowercase if anything is entered in CAPS print "Please enter your username: "; chomp($userN = <STDIN>); $username = lc($userN); print "Please enter your password: "; #hiding password system ("stty -echo"); chomp($passwd = <STDIN>); print "\n$passwd\n"; $matchCount = 0; #reading passwd.txt and assigning values while ($lines = <PSWD>){ ($user,$pswd,$userID,$groupID,$info,$home,$shell) = split ':', $li +nes; #checking username entered vs that in the passwd file if ($username eq $user){ print "Checking username... MATCH\n"; #keeps track if username matches or not $matchCount += 1; #checking password entered vs that in the passwd file if ($passwd eq $pswd){ print "Checking password... MATCH\n"; } else{ print "Password does not match!\n"; } last; } } # if matchcount did not change, username did not match killing the pro +gram if ($matchCount == 0){ die ("\"$username\" does not match any users in our database!\n"); } #opens accounting data file open (DATA, '<', 'IN-accounting.data'); #reading accounting data and assigning values while ($line = <DATA>){ ($lastName,$firstName,$ssn,$address,$city,$state,$zip,$payDate,$ho +urs,$rate,$taxes,$deductions,$notes) = split '|', $line; print "$lastName\n"; }
When I print $lastName, it only returns the first letter of the last name rather than the whole thing. If I was to print $lastname . $firstname, it would print the first 2 letters of the last name. Any ideas what is going on here?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Does split not work with a pipe?
by jethro (Monsignor) on Nov 09, 2012 at 17:16 UTC | |
|
Re: Does split not work with a pipe?
by Corion (Patriarch) on Nov 09, 2012 at 17:10 UTC | |
by jaffinito34 (Acolyte) on Nov 09, 2012 at 17:12 UTC | |
|
Re: [SOLVED] Does split not work with a pipe?
by Tanktalus (Canon) on Nov 10, 2012 at 14:37 UTC | |
|
Re: [SOLVED] Does split not work with a pipe?
by runrig (Abbot) on Nov 09, 2012 at 17:29 UTC |