Module, die automatisch Namen exportieren

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]

Passwd2.pm
package Passwd2;

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(getpwent_by_uid getpwent_by_login);

$passwd = "</etc/passwd";
open(PASSWD, $passwd) ||
   die "Unable to read from $passwd\n";
while(<PASSWD>) {
   chomp;
   ($login, $passwd, $uid, $gid,
      $name, $home, $shell) = split /:/;
   $passwd_by_uid{$uid} =
   $passwd_by_login{$login} = {
      login => $login, passwd => $passwd,
      uid => $uid, gid => $gid,
      name => $name, home => $home, shell => $shell
   };
}
close(PASSWD);

sub getpwent_by_uid { return $passwd_by_uid{$_[0]}; }
sub getpwent_by_login { return $passwd_by_login{$_[0]}; }

1;

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]
Copyright © 1996, 1998, 1999, 2000 Andreas Borchert, in HTML konvertiert am 07.02.2000