Click to See Complete Forum and Search --> : comparing the data in one file with the data in other file


rings
07-12-2007, 04:29 AM
i would like to know how to compare a data stored in one file with the data entered through stdin in other file. I have stored username and password in one file. Now i want to compare the that with the one entered through keyboard

CyCo
07-13-2007, 09:10 PM
Sounds like you just want to match username/password pairs. If that's the case, here's a very basic example:use strict;

my $un = '';
my $pw = '';

while ($un eq '') {
print 'Username: ';
chomp ($un = <STDIN>);
print "Enter username below...\n" if $un eq '';
}

while ($pw eq '') {
print 'Password: ';
chomp ($pw = <STDIN>);
print "Enter password below...\n" if $pw eq '';
}

while (<DATA>) {
chomp;
my ($u, $p) = split;
$un eq $u && $pw eq $p ? print uc("\ncongratulations!\n") : 0;
}

__DATA__
Tony a26b25
Chad c24d23
Mary e22f21