newbie-perl or why am i blind to this simple 
Author Message
 newbie-perl or why am i blind to this simple

ok so i'm new to perl and i'm trying to do what should be simple but i must
be blind. pointers requested, yes i do have the lama and camel books; but
like i said i must be blind. helpfull hints appreciated.

bill

 what i'm after:
 parse /etc/group
 pull out the usernames from a group (ask which group first)
 read /etc/passwd for the home dir
 reset the default group based on something (whatever,not germain to this)

what i get:
 ignores the last name in a group unless there is a trailing ,

to follow: code snippit, yea it's verbose but i'm trying to learn whats
happening so i expanded it.

#!/usr/lbin/perl
# this will pull the userid's out of /tmp/group based on the group name
# provided in response to a prompt. and it will look up info about them in
# /etc/passwd
#
print "For what group do you wish a list of members?\n";
 chop ($group_requested = <STDIN>);

open (FILENAME, "/tmp/group");
while (<FILENAME>)
 {


  {
  if (/^$group_requested/)
   {
   $group_name = $_;



    {

print "$login,$home\n";
    print "$user_id  ";
    print (getpwnam("$user_id"))[1-7];
    print "\n";
    }
#  print "$userid[3]\n";
   }
  }
 }
close (FILENAME);

bill pociengel

so what is the wow wow wibble wobble wozzey woddle woo?
'so what's a flame but a polite message reduced to it's essence?'
lilb pleceoing 'I'm a little confused right now'



Sat, 08 Mar 1997 06:37:01 GMT  
 newbie-perl or why am i blind to this simple

Quote:

>ok so i'm new to perl and i'm trying to do what should be simple but i must
>be blind. pointers requested, yes i do have the lama and camel books; but
>like i said i must be blind. helpfull hints appreciated.

 [problem is last username in a group is ignored]

Quote:
>#!/usr/lbin/perl
># this will pull the userid's out of /tmp/group based on the group name
># provided in response to a prompt. and it will look up info about them in
># /etc/passwd
>#
>print "For what group do you wish a list of members?\n";
> chop ($group_requested = <STDIN>);

>open (FILENAME, "/tmp/group");
>while (<FILENAME>)
> {


>  {
>  if (/^$group_requested/)
>   {
>   $group_name = $_;



                           ^^^^^^^^^^^^^
                           is probably better written as $grouplist[3]

$grouplist[3] will still have the trailing newline, so if the last

"mike\n".  You could use chop to get rid of the newline e.g.


{
  chop;

  ...

Quote:
}

Hope this helps,

Mike

--
The "usual disclaimers" apply.    | Meiko
Mike Stok                         | 130C Baker Ave. Ext

Meiko tel: (508) 371 0088 x124    |



Sat, 08 Mar 1997 19:52:10 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Why I am glad I know perl

2. I am a Perl Newbie.....need some help please

3. why am I trashing binary files with this?

4. Why am I getting an undefined subroutine error?

5. why am I having problems with mkdir

6. Why am I getting this regexp error?

7. Why am I getting an error with @_ ?

8. Why am I running out of memory?

9. Why am I stuck?

10. ? Now I am reaaly perplexed, Why doesn't (INDEX) work

11. Why am I dumping core???

12. Perl for the Blind

 

 
Powered by phpBB® Forum Software