home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!fmrco!fmrco!asherman
- From: asherman@laser.fmrco.com (Aaron Sherman)
- Subject: Re: how to get passwd
- In-Reply-To: tony@hacgate.SCG.HAC.COM's message of 31 Aug 92 23:39:53 GMT
- Message-ID: <ASHERMAN.92Sep2110720@laser.fmrco.com>
- Sender: news@fmrco.uucp
- Reply-To: asherman@fmrco.COM
- Organization: I-Kinetics, 19 Bishop-Allen Dr., Cambridge, MA
- References: <23093@hacgate.SCG.HAC.COM>
- Distribution: usa
- Date: Wed, 2 Sep 1992 16:07:20 GMT
- Lines: 43
-
-
- >>>>> tony@hacgate.SCG.HAC.COM (Tony Reeves) said:
-
- tony> I'm new to perl, so I'm sorry if this is a dumb question...
-
- There are no such things as dumb questions.
-
- tony> I want to read the last line of /etc/passwd and grep out the uid
- tony> number. I can't seem to do this. How can I do this easy? I
- tony> tryed open, seek and split. But it does not seem to work the
- tony> way I read it in the man page. Can a perl expert help me?
-
- That has to be the dumbest question I've ever heard in my life! ;-)
-
- How about:
-
- $\="\n";
- open(F,'</etc/passwd') || die("Cannot open /etc/passwd: $!\n");
- $last = $_ while(<F>);
- print((split(/:/,$last))[2]+0);
-
- or
-
- $\="\n";
- open(F,'</etc/passwd') || die("Cannot open /etc/passwd: $!\n");
-
- seek(F,-100,2);
- FIND:
- for($i=0;defined($c=getc(F)) && $c ne "\n" && $i < 100;$i++){1;}
- if ($c ne "\n") {seek(F,-200,1);goto FIND;}
-
- $last = $_ while(<F>);
- print((split(/:/,$last))[2]+0);
-
-
-
- -AJS
-
- --
- --------
- Disclaimer: I am solely responsible for the content of this message.
- The views expressed here may not be the views of I-Kinetics, Fidelity,
- any of the Fidelity-owned corporations or my mother.
-