in reply to Getting lines in a file between two patterns

hello and welcome to the monastery and to the wonderful world of Perl Daikini

the name of what you are looking for is strange: the flip flop operator.

A more serious description is 'bistable operator'. it is described in docs in the Range Operators.
The normal usage looks like:
while (<FH>) { print if $_ =~ /start/../end/ }
ie, as you can see it evaluates true (and in the example above it print because it evaluate true) only since 'start' is matched. It evaluates true until 'end' is matched, after 'end' is matched it evaluetes false.

Please note that for our convenience and hystorical reasons (?) if either opernads of flip-flop .. operator is constant it is considerd true if equal the current line number $. so if you write:
if (101 .. 200) { print; }
means:
if ($. == 101 .. $. == 200) { print; }
Or, in words: 'print only line from 101 to 200'.

Have also a read of Flipin good, or a total flop? and flip-flop interpolation

HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Getting lines in a file between two patterns
by Daikini (Initiate) on Oct 30, 2015 at 23:54 UTC
    So, I've implemented your code, which is getting me closer to the goal. Thank you for that.

    Here is what I've got running:

    while (<INPUT>){ if ($_ =~ /HISTORY/../TABLE/){ open(OUTPUT, '>'.$outputfile) or die "Can't create $output +file.\n"; print OUTPUT "$_\n"; close OUTPUT; } }

    The data I'm trying to pull out is in a table (in Word) and it will find the flip/flop, print it to the OUTPUT. That much is working. However, the data it returns is a jumbled mess of characters. It isn't intelligible.

    So, I tried saving a docx as rtf... no luck (it won't copy the table data, only gobbledegook), then I tried .txt... That returns the text/data, but I lose the neat and tidy layout of the table.

    Any suggestions on how to copy the table as a table or at least delimited somehow?

    Thank you again,
    Daikini

      You have your file-opening code inside the loop through each line. It should be moved outside, so the file is only opened once instead of once for every line (and overwritten each time), and also would be better written as:

      open my $OUTPUT, '>', $outputfile or die "File open fail: $!\n";
      See open.

      As far as your data foramtting question, you probably should use a module for reading your Windows file format, maybe Win32::OLE? (disclaimer: I haven't programmed with Windows for years; search CPAN and you'll almost certainly find what you need if that's not it.)

      Hope this helps!

      The way forward always starts with a minimal test.
Re^2: Getting lines in a file between two patterns
by Daikini (Initiate) on Oct 30, 2015 at 16:50 UTC
    Thank you very much, Discipulus, for the quick reply. I'll give this a shot and let you know how I do.