I have tried to rewrite an old short Perl script, that reads a Unix
password file, and prints loginname and realname if the userid number
is greater than 100. The Perl script is here:
#!/usr/bin/perl
open (PASSWD,"/etc/passwd") || die ("Can't open passwd file!");
@passwd = <PASSWD>;
close (PASSWD);
foreach (@passwd) {
@userdata = split(/:/,$_);
if (@userdata[0] =~ /^#/) {
next;
}
if (@userdata[2] > 100) {
printf "%12s %30s\n", @userdata[0], @userdata[4];
}
}
# Script ends
I have been reading "Programming Ruby" written by The Pragmatic
Programmers, and
I have no trouble opening the password file, and I can also print the
file content to the screen. I am having a problem writing the loop the
"Ruby way".
I will appreciate, if someone takes the time and helps me getting
further with my attempts on programming Ruby.
/Allan