hotshot,

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


In reply to Re: getpwXXX by derby
in thread getpwXXX by hotshot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.