So i'm trying to use getpwnam() to search etc/passwd for a username in a sub, and return true if it exists. I keep getting the error "Use of uninitialized value in getpwnam".
sub nameSearch
{
$search = $_;
@name = getpwnam($search);
if ( ! defined $name[0])
{
return 0;
}
else
{
return 1;
}
}
I'm passing a chomped string into this sub. I've tried just using @name = getpwnam($_[0])
and @name = getpwnam($_)
I know as a fact that string i'm passing exists as a username in /etc/passwd and the code works when its not in a sub.