in reply to getpwXXX
or have some fun with the c function fgetpwent and INLINE
#!/usr/local/bin/perl -w use Inline C; use Data::Dumper; @ARGV || die "usage $0 <filename>\n"; $entries = getmypwent($ARGV[0]); print Dumper( $entries ); __END__ __C__ #include <pwd.h> #include <stdio.h> #include <sys/types.h> SV *getmypwent( char *filename ) { FILE *ih; struct passwd *p; int len; AV *array; HV *hash = newHV(); if( ( ih = fopen( filename, "r" ) ) != NULL ) { while( p = fgetpwent( ih ) ) { hv_store(hash, p->pw_name, strlen(p->pw_name), newRV_noinc((SV*)array = newAV()), 0); av_push(array, newSVpvf("%s", p->pw_passwd)); av_push(array, newSVpvf("%d", p->pw_uid)); av_push(array, newSVpvf("%d", p->pw_gid)); av_push(array, newSVpvf("%s", p->pw_gecos)); av_push(array, newSVpvf("%s", p->pw_dir)); av_push(array, newSVpvf("%s", p->pw_shell)); } fclose(ih); } return newRV_noinc((SV*) hash); }
-derby
|
|---|