Add getpwent() example to perl

pull/141/head
terminalforlife 4 years ago
parent 52e621be4e
commit 08a6f38fe7

@ -58,3 +58,11 @@ perl -e 'print("$<:" . (split(" ", $)))[0] . "\n")'
# You might spot some printable strings, such as 'LILO' or 'GRUB', if you've
# also stored your bootloader on the MBR of the storage device (non-UEFI).
perl -e 'open(my $FH, "</dev/sda"); read($FH, my $Data, 512); close($FH); print("$Data\n")'
# Create a simple table of users within your system. This example demonstrates
# the use of the `getpwent()` subroutine, which, upon each execution, holds an
# array of each field in each line within the '/etc/passwd' file.
printf("%-15s %-5s %-5s %-s\n", 'USERNAME', 'UID', 'GID', 'HOME');
while (my @Data = getpwent()) {
printf("%-15s %-5s %-5s %-s\n", $Data[0], $Data[2], $Data[3], $Data[7])
}

Loading…
Cancel
Save