Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!uunet!bfmny0!tneff From: tneff@bfmny0.BFM.COM (Tom Neff) Newsgroups: comp.lang.perl Subject: Re: Reading a file into a string Message-ID: <97130173@bfmny0.BFM.COM> Date: 30 Jan 91 01:09:22 GMT References: <1991Jan30.005821.13013@convex.com> <97130172@bfmny0.BFM.COM> <11235@jpl-devvax.JPL.NASA.GOV> Reply-To: tneff@bfmny0.BFM.COM (Tom Neff) Lines: 34 Sorry to requote all 5, but Allah forbid someone gets this out of order :-) In article <11235@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: |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. ... However, 4) and 5) don't work on pipes, named or unnamed. 1) works on named pipes but not unnamed. Only 2) and 3) work everywhere. -- Annex Canada now! We need the room, \) Tom Neff and who's going to stop us. (\ tneff@bfmny0.BFM.COM