[comp.lang.perl] Why doesn't this work????

mfrost@pyrps5.pyramid.com.pyramid.com (Mark Frost) (11/20/90)

I'm trying to write this script that checks to make sure that each user in
the passwd file is in the group that their password entry says they are. The
script is shown below. I seem to be getting stuck trying to match the login
name with the list of users in a group. This is coming from the line

	if ( $grmembers =~ /$name/ ) {

below. I'm stumped, I don't know why this fails.
Here is the output I get when I run it now (yes, it quits quickly so I can
debug it). Names have been changed to protect the innocent

grmembers ->root adm operator usera userb userc userd usere userf userg
name ->root
root is not in the root group

Now here's the script...

Thanks greatly for your help!!!!

          -m-----------  Mark Frost    (mfrost@pyramid.com)
        ---mmm---------  System Administrator - Hardware Engineering
      -----mmmmm-------  Pyramid Technology Corporation
    -------mmmmmmm-----  1295 Charleston Rd, P.O. Box 7295
  ---------mmmmmmmmm---  Mountain View, California 94039-7295 
-----------mmmmmmmmmmm-  (415) 335-8163


#!/usr/bin/perl
#
# This script checks to make sure that a user is in the group that the passwd
# file says they are actually in.
#

$|=1;
$passwd="/etc/passwd";

open (pw,"$passwd") || die "Can't seem to open $passwd\n";
while (<pw>) {
	chop;
	($name,$passwd,$uid,$gid,$gcos,$home,$shell) = split(/:/);
	($grname, $grpasswd, $grgid, $grmembers) = getgrgid($gid);

	print "grmembers ->$grmembers\n";
	print "name ->$name\n";
	if ( $grmembers =~ /$name/ ) {
		print "$name is not in the $grname group\n";
		exit(0);
	} # if

} # while
close (pw);
exit 0;