#!/usr/bin/perl
##Write a program to open the /etc/passwd file by name and print out the username, user ID (number), and real name in formatted columns. Use format and write.
use strict;
use warnings;
my $username;
my $ID;
my $realname;
format OUTFILE =
====================================
| @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
"username:".$username
| @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
"ID:".$ID
| @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
"realname:".$realname
====================================
.
open PASS,"/etc/passwd" or die "Can't.";
open OUTFILE,">format.log" or die "Can't.";
while(
){
chomp;
my @items = split(/:/);
$username = $items[0];
$ID = $items[1].":".$items[2].":".$items[3];
$realname = $items[4];
write (OUTFILE);
}
result:
# head format.log
====================================
| username:root |
| ID:x:0:0 |
| realname:root |
====================================
====================================
| username:bin |
| ID:x:1:1 |
| realname:bin |
====================================
阅读(904) | 评论(0) | 转发(0) |