* Anthony J. Breeds-Taurima ([EMAIL PROTECTED]) [010926 23:14]: > <== randline ==> > #!/usr/bin/perl > ## print 1 randomline from a file > @_=<>; > print $_[rand$#_];
while this one works, the one Martin posted is a better solution. They're both O(n) in terms of time, but Martin's is O(1) wrt space, whereas this one is Also O(n) -- it reads in and stores the entire file and then picks out a line. Unfortunately, it doesn't lend itself as well to extension to the case of "shuffling a file". But for one random line from a file, it's a very elegant solution. See the archives for more discussion. -- Vineet http://www.anti-dmca.org Unauthorized use of this .sig may constitute violation of US law. echo Qba\'g gernq ba zr\! |tr 'a-zA-Z' 'n-za-mN-ZA-M'
pgpA8470FqfIh.pgp
Description: PGP signature