in reply to Finding part of a file

update: changed chop to chomp on Aighearach's suggestion, which is of course very sensible, as one doesn't know for sure that the record separator will only be one character.

AFAIK you have to read through the file. You can only pull out a pre-determined fragment of the file if you know its location in bytes. Then you would use seek and read. But unless it's a huge file, there's no harm in doing something like
my $start = 'banana'; my $end = 'grape'; my $get = 0; my @results; open FILE, "file.txt"; while (<FILE>) { chomp; $get = 0 if $_ eq $end; push @results, $_ if $get; $get = 1 if $_ eq $start; } print $_,"\n" for @results;
You'd need something a little more subtle if you aren't sure that 'banana' comes before 'grape' or you think one or other might be absent altogether.

§ George Sherston

Replies are listed 'Best First'.
Re: Re: Finding part of a file
by Aighearach (Initiate) on Dec 04, 2001 at 21:02 UTC
    You might want to consider chomp instead of chop
    --
    Snazzy tagline here