Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: Accessing a file from the perl

by abcdefg (Acolyte)
on Jan 12, 2012 at 00:03 UTC ( [id://947457]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Accessing a file from the perl
in thread Accessing a file from the perl

$user = <$client_socket>; chomp($user); #remove the \n print "$prefix USER = $user\n"; unless (open (USERNAME, "username")) { print "ERROR:Cannot open username file.\n"; exit(1); # ERROR } my $found; while(my $newusername = <USERNAME>) { chomp($newusername); if($newusername eq $user) { $found = 1; last; } unless ($found) { print $client_socket "ERR\n"; print "$prefix ERROR: user $user not allowed Exiting. +\n"; close(USERNAME); exit(1); } } #else, continue print $client_socket "ACK\n"; # approve the user. #print "user $user is allowed."; close(USERNAME);

I tried what you said as above but still it got same problem..still its not goin on else part where user is approved.

Replies are listed 'Best First'.
Re^4: Accessing a file from the perl
by Eliya (Vicar) on Jan 12, 2012 at 00:11 UTC

    The unless ($found) check needs to be after the while loop, not within  (before having run through the entire file, you cannot tell whether a matching entry was found...)

      thanks a lot eliya..it worked.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://947457]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-19 16:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found