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?


In reply to [SOLVED] Does split not work with a pipe? by jaffinito34

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.