Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: I'm lazy, can this be done somehow??? Message-ID: <11210@jpl-devvax.JPL.NASA.GOV> Date: 28 Jan 91 22:44:43 GMT References: <1991Jan26.012646.4937@sdd.hp.com> <1991Jan26.154656.4794@NCoast.ORG> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Distribution: na Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 39 In article <1991Jan26.154656.4794@NCoast.ORG> allbery@ncoast.ORG (Brandon S. Allbery KB8JRR) writes: : As quoted from <1991Jan26.012646.4937@sdd.hp.com> by harless@sdd.hp.com (Mike Harless): : +--------------- : | $[ = 400 ; : | @found = grep(/whatever/, @lines) ; : | : | and only have grep work on the lines after the first 400. I know that : | I could do this by using an index into @lines, but was trying to do : | things elegantly. I've heard rumors that using indices into arrays isn't : | the perl way! :-) Is there something simple that I missed? : +--------------- : : Use a slice: : : @found = grep(/pattern/, @lines[$start .. $#lines]); : : (Note the @. @name[...] and $name[...] are different.) : : Although I do admit that I've thought $[ should work like this. $[ only changes the offset to the first element. It doesn't affect the contents of the array at all. Another way to get rid of the first 400 lines is to say splice(@lines,0,400); In general, though, problems like this are best handled by recording the byte offset to start up again and then seeking to the correct location. Slurping in the front of the file when you aren't interested in it is bound to be somewhat boring. Another tack I've taken on huge log files is to search backwards from the end of the file forwards. Do that scan in large hunks until you get before you want to be, then scan forward normally for the line to start on. This presumes there's some kind of ordered key, such as the date in the news history file. Larry