I am comparing the passwd file to a file of numbers. The numbers match GECOS info in the passwd file. I want the lines in the passwd file not matching lines in the $students file printed to another file. I used examples of others code to come up with the following. It works OK. My problem is that the data in /etc/passwd is quite variable and so sometimes I have nothing in $two, and sometimes it is not what I want (i.e. the line with "Jr."). Can someone educate me on a way to split conditionally, as in split on the character before a number ?
#!/usr/bin/perl -w use strict; my ($one, $two, $three, $four, $five, $six, $line, $pair); my $dir = "/usr/local/tools"; my $pwlist = "/etc/passwd"; my $students = "$dir/spr2007.txt"; my %sids; open my($numbers), $students or die "can't read $students: $!"; open my($pfile), $pwlist or die "can't read $pwlist: $!"; while (<$numbers>) { chomp; $sids{$_} = 1; } close $numbers; open (RESULTS, "+>$dir/students_to_modify.txt"); my @line = <$pfile>; foreach $pair (@line) { ($one, $two, $three, $four, $five, $six) = split(/:/, $pair); ($one, $two, $three) = split(/,/, $five); $two =~ s/^\s+//; printf RESULTS ("$two, $one, $three\n") unless $sids{$two}; } close $pfile; close RESULTS; Here is an example of $students : 123 1234567 12334 300901 Here is an example of $pwlist (other than the usual entires): nhl:*:15739:15739: Norm E Hill, Jr. , 123404 , FG-04 :/usr/nhl:/bin/nologin rmaya:*:15742:15742: Ruika Manya , 24540 , QW-27 :/usr/rmaya:/bin/nologin lpea:*:15755:15755:Luci Pea, NOID, Art, 1985:/usr/lpea:/bin/nologin jpos:*:15758:15758:Jose Pos,12334,AR-34:/usr/jpos:/bin/nologin bmier:*:15760:15760:Bennet Mier, Jr.,300901,AA-18:/usr/bmier:/bin/nologin cotght:*:15762:15762:Tami Cotght,123333,ZZ-08:/usr/cotght:/bin/nologin gcale:*:15763:15763:Gin Calebary,2448,BB-157:/usr/gcale:/bin/nologin studc:*:15764:15764:Student Council,Student Affairs,Special:/usr/studc:/bin/nologin blackc:*:15768:15768:Black Clock,Bob Foser,Special:/usr/blackc:/bin/nologin jiee:*:15791:15791:JiYeo Lee:/usr/jiee:/bin/nologin mfa04:*:15794:15794:Karen Ason:/usr/mfa04:/bin/nologin -- Karyn Williams Network Services Manager California Institute of the Arts [EMAIL PROTECTED] http://www.calarts.edu/network -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/