One approach is to read more than a line at a time. You could set $/ to read in a record at a time, which is made easier if there's a blank line or some other marker between records.
Another approach is to read the entire file into a scalar, by localizing $/ within a block, reading the file into a scalar, and then using multi-line regexes.
You could read the entire file into an array, loop through with an index variable, incrementing the index as necessary, or building up a second array of lines.
Similarly, you could loop through a line at a time, building a single array, appending a continued line.
Depending on how large the file is, you might want to continue processing a line at a time. I would probably do something like this pseudo-code:
This depends on a lot of specifics, but you get to process (basically) a line at a time for the small overhead of keeping a little bit of state information around.# open file # declare a last_line variable # loop, reading a line at a time # check to see if line is continued # if so, append the current item to the last_line variable # set a flag that we've done this # process last_line (in another function, probably) # stick the current line in last_line # if the flag is set, empty out last_line
In reply to Re: Look ahead and comp if pattern matches next line
by chromatic
in thread Look ahead and comp if pattern matches next line
by Er1kW
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |