home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5730 < prev    next >
Encoding:
Internet Message Format  |  1992-09-04  |  1.9 KB

  1. Path: sparky!uunet!sun-barr!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!reed!romulus!merlyn
  2. From: merlyn@ora.com (Randal L. Schwartz)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: how to get passwd
  5. Message-ID: <MERLYN.92Sep4120357@romulus.reed.edu>
  6. Date: 4 Sep 92 19:04:02 GMT
  7. Article-I.D.: romulus.MERLYN.92Sep4120357
  8. References: <23093@hacgate.SCG.HAC.COM> <ASHERMAN.92Sep2110720@laser.fmrco.com>
  9.     <1992Sep3.184343.12651@netlabs.com>
  10.     <ASHERMAN.92Sep4130521@laser.fmrco.com>
  11. Sender: news@reed.edu (USENET News System)
  12. Distribution: usa
  13. Organization: Stonehenge Consulting Services; Portland, Oregon, USA
  14. Lines: 43
  15. In-Reply-To: asherman@laser.fmrco.com's message of 4 Sep 92 18:05:21 GMT
  16.  
  17. In article <ASHERMAN.92Sep4130521@laser.fmrco.com> asherman@laser.fmrco.com (Aaron Sherman) writes:
  18.    What's faster (and/or smaller and/or more efficient) than this:
  19.  
  20.        $\="\n";
  21.        open(F,'</etc/passwd') || die("Cannot open /etc/passwd: $!\n");
  22.  
  23.        if (seek(F,-100,2))
  24.        {
  25.            do
  26.            {
  27.            $i=0;
  28.            while(defined($c=getc(F)) && $c ne "\n")
  29.            {
  30.                last unless ($i++ < 100);
  31.            }
  32.            } while($c ne "\n" && seek(F,-200,1));
  33.        }
  34.  
  35.        seek(F,0,0) if (tell < 100);
  36.        $last = $_ while(<F>);
  37.        print((split(/:/,$last))[2]+0);
  38.  
  39.  
  40. Argh. "getc"??  That's *easy* to beat!
  41.  
  42. open(F,"/etc/passwd") || die "Better not log out!";
  43. $try = 512;
  44. {
  45.     seek(F,-$try,2);
  46.     $last = $this = "";
  47.     <F>; # skip to next newline
  48.     $last = $this while $this = <F>; # read until we see eof
  49.     last if $last; # good run
  50.     $try += 512; # bigger bite backward
  51.     redo; #once more
  52. }
  53. print ((split(/:/,$last))[2]); # why add zero?  foo!
  54.  
  55. "Just another Perl hacker,";seek(DATA,1,0);read(DATA,$_,25);print;__END__
  56. --
  57. Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
  58. merlyn@reed.edu (guest account) merlyn@ora.com (better for permanent record)
  59. cute quote: "Welcome to Portland, Oregon -- home of the California Raisins!"
  60.