Date: 14 Sep 2001 06:47:01 GMT From: damian@qimr.edu.au (Damian James) Subject: Re: Perl (slurping) is TOO much fun Message-Id: Benjamin Goldberg chose Fri, 14 Sep 2001 00:21:11 -0400 to say this: >Zachary Kent wrote: >> >> > (BTW this is not advocating slurping files, just something I do >> sometimes). >> >> Wha? Is slurping considered bad programming practice (as well as bad >> manners at the table)? What is the better solution? I gotta read >> these posts more often... > >When you slurp in a file, it can take up quite a bit of memory. When >you read and process a file line by line, you use less memory. So it depends on how mauch RAM you have, and and how big the file is. If you have plenty of RAM to spare after loading the entire file into memory, then slurping can be the faster and easier option. However, if the file is so large that you don't have enough RAM to load it, then obviously slurping is not feasible. And some operations are MUCH harder to do without slurping. Consider something as everyday as sorting. I say slurp when you can -- which is whenever you are sure the file won't become too big (for values of 'too big' that are appropriate to your system, taking into account the overheads of the OS, Perl and how many users there will be at any one time). Even then, for some operations it will be easier to slurp for now, then later tie() your data structure to a disk file. Remember that these days RAM is cheap and you need a lot of data to use it up. And reading from RAM is much faster than reading from disk. Cheers, Damian -- @:=grep!(m!$/|#!..$|),split//,;@;=0..$#:;while($:=@;){$;=rand $:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,, $,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__ Just another Perl Hacker, ### rev 3.3 -- stupidectomy performed :-)