Fonction setpwent de Perl

La description

Cette fonction définit (ou réinitialise) l'énumération au début de l'ensemble d'entrées de mot de passe. Cette fonction doit être appelée avant le premier appel à getpwent.

Syntaxe

Voici la syntaxe simple de cette fonction -

setpwent

Valeur de retour

Cette fonction ne renvoie aucune valeur.

Exemple

Voici l'exemple de code montrant son utilisation de base -

#!/usr/bin/perl

while(($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, 
   $shell) = getpwent()) {
   print "Name = $name\n";
   print "Password = $passwd\n";
   print "UID = $uid\n";
   print "GID = $gid\n";
   print "Quota = $quota\n";
   print "Comment = $comment\n";
   print "Gcos = $gcos\n";
   print "HOME DIR = $dir\n";
   print "Shell = $shell\n";
}

setpwent() ; # Rewind the databse /etc/passwd

while(($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, 
   $shell) = getpwent()) {
   print "Name = $name\n";
   print "Password = $passwd\n";
   print "UID = $uid\n";
   print "GID = $gid\n";
   print "Quota = $quota\n";
   print "Comment = $comment\n";
   print "Gcos = $gcos\n";
   print "HOME DIR = $dir\n";
   print "Shell = $shell\n";
}

endpwent(); # Closes the database;

Lorsque le code ci-dessus est exécuté, il produit le résultat suivant -

Name = root
Password = x
UID = 0
GID = 0
Quota = 
Comment = 
Gcos = root
HOME DIR = /root
Shell = /bin/bash
Name = bin
Password = x
UID = 1
GID = 1
Quota = 
Comment = 
Gcos = bin
HOME DIR = /bin
Shell = /sbin/nologin
Name = daemon
Password = x
UID = 2
GID = 2
Quota = 
Comment = 
Gcos = daemon
HOME DIR = /sbin
Shell = /sbin/nologin
.
.
.
Name = qemu
Password = x
UID = 107
GID = 107
Quota = 
Comment = 
Gcos = qemu user
HOME DIR = /
Shell = /sbin/nologin
Name = com
Password = x
UID = 501
GID = 501
Quota = 
Comment = 
Gcos = 
HOME DIR = /home/com
Shell = /bin/bash
Name = railo
Password = x
UID = 497
GID = 495
Quota = 
Comment = 
Gcos = 
HOME DIR = /opt/railo
Shell = /bin/false