Hi Experts,
I am having some problem in removing the newline character from the string that is read from a text file. I have the source code below. The problem is if I have the username password pair as myname:password it says that the password has 9 characters. The chomp seems to not remove the newline character. Please provide me with some advice as to solve the problem. This problem preventing me from going further with my assignment.
Thanks a lot,
-Thanesh
#!/usr/bin/perl --
use CGI qw( :standard );
$dtd =
$theUsername = param( "username" );
$thePassword = param( "password" );
open(INFILE, "<password.txt") or die("The database could not be opened.");
$count = 0;
$userVerified = 0;
$passwordVerified = 0;
chomp $thePassword;
while (( $line =<INFILE> ) && (!$userVerified )) {
$count = $count + 1;
chomp( $line );
( $username, $password ) = split( /:/, $line );
chomp($password);
chomp($username);
print( header() );
print("<br>");
if ( $theUsername eq $username ) {
print("User name matches");
print("<br>");
$userVerified=1;
$len = (length($password));
print("Length of password is: $len");
print("<br>");
$theLen = (length($thePassword));
print("Lenth of input password is: $theLen");
print("<br>");
if ( $thePassword eq $password ) {
print("Password matches");
print("<br>");
$passwordVerified = 1;
last;
}
print("The password don't match");
}
}
close(INFILE);
print( header() );
#print( start_html( { dtd => $dtd,title => "First Perl Script" } ) );
print("thePassword: $thePassword");
print("The user name is: $theUsername\n\n");
print("<br>");
print("The user name is verified: $userVerified\n");
print("<br>");
print("The password is verified: $passwordVerified\n");
print("<br>");
print("The password is: $password");
print("<br>");
print("The user name processed: $username");
print("<br>");
print("The count is: $count");
#print( end_html() );
Start Free Trial