Nick Drage wrote: > > On Tue, Mar 04, 2003 at 11:24:55AM -0000, Rob Dixon wrote: > > > > @rgstr=<HoyIn>; > > > > This puts the <> operator into list context, so it will read > > all of the file, placing separate records into consecutive > > elements of the array. If this is what you want to do, then > > you have finished with the file already and you can close > > it here: > > I presume if I change "$/" the definition of what constitutes a record will > change also?
Yes. > So an element in the array can contain newlines? If the file you are reading from contained newlines then the data in an array or scalar will contain newlines unless you remove them. > > However, sucking all of the file into memory may be a > > bad idea, especially if it is a large file. In this case you > > can use a while loop on the filehandle: > > I've seen this advice before, but how big is a "large file"? I mean I know > this depends on the available memory, but presumably a few kilobytes or even > megabytes won't cause too much of a strain? In most cases you don't NEED to slurp the entire file into memory. > > Since you're using <> in a scalar context here it will read > > individual lines into the $_ variable. The while condition > > will succeed until you reach end-of-file, and the > > conditional > > > > if 5..eof > > > > will succeed on or after line number 5 until end-of-file. > > How about if you want to pass lines 5 to 25 into an array, what's the best > way to do that? my @array; while ( <HoyIn> ) { push @array, $_ if 5 .. 25; last if $. == 25; } > Or what I'm really after, how to pass everything between two strings into an > array? my @array; while ( <HoyIn> ) { push @array, $_ if /string one/ .. /string two/; last if /string two/; } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]