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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.