in reply to Re: User Existance?
in thread User Existance?

Thanks for that. Using the regexp method, how would i apply it to this custom made file:
user1 user2 user3 user4 user5,pass5,email5,ip5 user5,pass5,email5,ip5 user5,pass5,email5,ip5 user5,pass5,email5,ip5 user5,pass5,email5,ip5
As you can see, the file varies slightly. So i want the regexp to open up the file (located at /etc/adduser/user.log) and match $username against the first part (userX) of each line. If there is a match, print an error.

Cheers peeps, The help is massivly appreciated :)

Replies are listed 'Best First'.
Re: Re: Re: User Existance?
by The Mad Hatter (Priest) on May 17, 2003 at 18:52 UTC
    Probably a better way to do this, but here's one way:

    Update So getpwnam is faster? Ok...

    my $username = "usernamehere"; print "Duplicate!\n" if getpwnam($username);
    my $username = "user1"; while (<DATA>) { chomp; my @info = split ","; foreach (@info) { print "Duplicate!\n" if /\A\Q$username\E\z/ } } __DATA__ user1 user2 user3 user4 user5,pass5,email5,ip5 user5,pass5,email5,ip5 user5,pass5,email5,ip5 user5,pass5,email5,ip5 user5,pass5,email5,ip5
      why am i getting an error when trying to run this?
      if getpwnam($username) { $message = $message.'<p>The Chosen Username Already Exists.</p>'; $found_err = 1; }
        You need parentheses around the conditional statement for the if...
        if (getpwnam($username)) { $message = $message.'<p>The Chosen Username Already Exists.</p>'; $found_err = 1; }