in reply to getpwXXX
or you can iterate through the file & split out each line like so:open FH, '/etc/passwd' or die "Can't open /etc/passwd, $!"; my @matches = grep { chomp; /thing_to_match/ } <FH>;
The following code mimics getpwnam:while (<FH>) { chomp; my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = split /:/; }
If you really don't want to do it yourself, tilly's Text::xSV module could be your answer.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]; }
Update: Added a missing brace & stuck in an error check
|
|---|