CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: just starting out, comparing two arrays: Edit Log



scottmusician
New User

Jun 23, 2013, 6:17 AM


Views: 506
just starting out, comparing two arrays

Hi all,

This is my first post!

I've just started a perl class, and I'm trying to write a simple script to optimize the /etc/groups file, to make sure that it only contains entries that also exist in /etc/passwd .

here's what I have so far, but it all seems a little cumbersome. Any thoughts would be great!

Thanks,
Scott


Code
#!/usr/local/bin/perl 

open(F, "/etc/passwd");
@passwd = <F>;
chop(@passwd);
open(F, "/etc/group");
@group = <F>;
chop(@group);

for ($i=0; $i<$#group; $i++) {
$line = $group[$i];
$line =~ /^(..*):(..*):(..*):(..*)$/;
($group, undef, undef, $members) = ($1, $2, $3, $4);
@members = split(/,/, $members);
foreach $m (@members) {
printf("%s\n", $m) unless grep(/^$m:/, @passwd);
}
}



(This post was edited by scottmusician on Jun 23, 2013, 6:23 AM)


Edit Log:
Post edited by scottmusician (New User) on Jun 23, 2013, 6:23 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives