Hi,

Perl has a built in function that do just that:

if (my $username = getpwuid($input_uid)) {
     print "Founf the user $username\n";
} else {
      print "No user found\n";
}

for help try
perldoc -f getpwent
perldoc -f getpwnam
perldoc -f getpwuid

BFN

Yaron Kahanovitch


----- Original Message -----
From: "snickwad" <[EMAIL PROTECTED]>
To: beginners@perl.org
Sent: Thursday, July 26, 2007 1:14:49 PM (GMT+0200) Africa/Harare
Subject: Test if string does not exist in an array.

Apologies if this is a bit noobie, but I have been left with a short
window to write a tool and I have had no experience with Perl. Very
familiar with Kornshell, and so far my Perl script is going okay.
However, I am struggling to get a test working correctly. Is there a
simple way to test if a string does not exist in an array?

I am trying to test if some user input (a userid) is valid and error
if it does not exist. Currently have the contents of /etc/passwd in an
array, and can test for valid users, but all my efforts to test for
invalid have failed miserably.

I am on AIX, not sure on the Perl version.

Current test for valid is :

return 1 if (grep(/$user/,$udata));

Any help would be much appreciated.

Ashley


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to