Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: Reading a file into a string Message-ID: <11235@jpl-devvax.JPL.NASA.GOV> Date: 30 Jan 91 19:24:53 GMT References: <5231@taux01.nsc.com> <1991Jan30.005821.13013@convex.com> <97130172@bfmny0.BFM.COM> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 26 In article <97130172@bfmny0.BFM.COM> tneff@bfmny0.BFM.COM (Tom Neff) writes: : In article <1991Jan30.005821.13013@convex.com> tchrist@convex.COM (Tom Christiansen) writes: : >1) $foo = `cat $file`; : > : >2) open (FILE, $file); : > undef $/; : > $foo = ; : > close(FILE); : : 3) open (FILE, $file); $foo = ''; : while (!eof(FILE)) { read(FILE, $x, 32767); $foo .= $x;}; : : You can use bigger numbers than 32767... You sure can, including the size of the file: 4) open(FILE, $file); read(FILE, $foo, -s $file); or better in two ways, 5) open(FILE, $file); sysread(FILE, $foo, -s FILE); I sincerely doubt that any other construct is going to beat that, timewise. (Solutions using syscall(SYS_mmap...) not allowed. :-) Larry