If you want to be certain that your script only searches
a local /etc/passwd file, you'll have to do it yourself.
On the bright side, it's not hard to do that:
open FH, '/etc/passwd' or die "Can't open /etc/passwd, $!";
my @matches = grep { chomp; /thing_to_match/ } <FH>;
or you can iterate through the file & split out each line
like so:
while (<FH>) {
chomp;
my ($name, $passwd, $uid, $gid, $quota, $comment,
$gcos, $dir, $shell) = split /:/;
}
The following code mimics getpwnam:
sub my_getpwnam {
my $name_m = shift;
open FH, '/etc/passwd' or die "Can't open /etc/passwd, $!";
my @match = grep { chomp; /^$name_m:/ } <FH>;
if (!@match) { return (); } # return empty list if not found
return split /:/, $match[0];
}
If you really don't want to do it yourself, tilly's
Text::xSV module
could be your answer.
Update: Added a missing brace & stuck in an error
check |