home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!reed!romulus!merlyn
- From: merlyn@ora.com (Randal L. Schwartz)
- Newsgroups: comp.lang.perl
- Subject: Re: how to get passwd
- Message-ID: <MERLYN.92Sep4120357@romulus.reed.edu>
- Date: 4 Sep 92 19:04:02 GMT
- Article-I.D.: romulus.MERLYN.92Sep4120357
- References: <23093@hacgate.SCG.HAC.COM> <ASHERMAN.92Sep2110720@laser.fmrco.com>
- <1992Sep3.184343.12651@netlabs.com>
- <ASHERMAN.92Sep4130521@laser.fmrco.com>
- Sender: news@reed.edu (USENET News System)
- Distribution: usa
- Organization: Stonehenge Consulting Services; Portland, Oregon, USA
- Lines: 43
- In-Reply-To: asherman@laser.fmrco.com's message of 4 Sep 92 18:05:21 GMT
-
- In article <ASHERMAN.92Sep4130521@laser.fmrco.com> asherman@laser.fmrco.com (Aaron Sherman) writes:
- What's faster (and/or smaller and/or more efficient) than this:
-
- $\="\n";
- open(F,'</etc/passwd') || die("Cannot open /etc/passwd: $!\n");
-
- if (seek(F,-100,2))
- {
- do
- {
- $i=0;
- while(defined($c=getc(F)) && $c ne "\n")
- {
- last unless ($i++ < 100);
- }
- } while($c ne "\n" && seek(F,-200,1));
- }
-
- seek(F,0,0) if (tell < 100);
- $last = $_ while(<F>);
- print((split(/:/,$last))[2]+0);
-
-
- Argh. "getc"?? That's *easy* to beat!
-
- open(F,"/etc/passwd") || die "Better not log out!";
- $try = 512;
- {
- seek(F,-$try,2);
- $last = $this = "";
- <F>; # skip to next newline
- $last = $this while $this = <F>; # read until we see eof
- last if $last; # good run
- $try += 512; # bigger bite backward
- redo; #once more
- }
- print ((split(/:/,$last))[2]); # why add zero? foo!
-
- "Just another Perl hacker,";seek(DATA,1,0);read(DATA,$_,25);print;__END__
- --
- Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
- merlyn@reed.edu (guest account) merlyn@ora.com (better for permanent record)
- cute quote: "Welcome to Portland, Oregon -- home of the California Raisins!"
-