<> Hello,
i have a code below which intends to populate an array using File Handle, and File handle contains the linux passwd file info separated by ":". I am able to succeed till this point.
Now, i further need to split each passwd line and extract UID and GID for each user. i am able to achieve this only for the first line of passwd file, and not for rest others. Below is the code and the passwd file i am using, please guide, where am i wrong.
$HAN = "handle";
$FILE = "passwd.txt";
open("$HAN", "$FILE")||die "Error opening file: $!\n";
while(<$HAN>) {
@arr = <$HAN>;
}
foreach(@arr) {
@IDINFO = split(/:/,"$arr[$_]");
print "UID is: @IDINFO[2] \n";
print "GID is: @IDINFO[3] \n";
}
Passwd File, i am using:
xerox:x:10532:151:simmy
xrsa:x:222:507:SystemExpert
hintest:x:32381:1873:xThin
xtactid:x:65446:266:eVenues
ricpay:x:30197:1168:Emeral
way:x:10010:111:Expressway
t061gs:x:80061:3415:Gurav
e456988:x:38975:3477:center
zrmda01:x:137001:137:Domino
lmda02:x:137002:137:Domino
TYMFTP:x:51331:2130:Customer
ddda03:x:137003:137:Domino
ddda04:x:137004:137:Domino
dda05:x:137005:137:Domino
dda06:x:137006:137:Domino
ddm01:x:88085:137:Notes
output: (its only taking first line and printing multiple times)
UID is: 222
GID is: 507
UID is: 222
GID is: 507
UID is: 222
GID is: 507
UID is: 222
GID is: 507
UID is: 222
GID is: 507
UID is: 222
GID is: 507
UID is: 222
GID is: 507
UID is: 222
GID is: 507
UID is: 222
GID is: 507
UID is: 222
GID is: 507
UID is: 222
GID is: 507
UID is: 222
GID is: 507
UID is: 222
GID is: 507
UID is: 222
GID is: 507
UID is: 222
GID is: 507
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.