There is a construct in perl that actually means "between", it is the range operator '..'.

open my $handle, "<", $ARGV[0] or die "Couldn't open file: $!"; # safe +r way to open a file for reading. while (<$handle>) { if (/CREATE TABLE/../-----/) # if between CREATE TABLE and ----- { # Some code } }
See also the way I opened and read from the file, which is both safer and clearer than what you did, (you can still put the lines in an array by doing: my @lines = <$handle>; and then iterate over the array).

As for the rest of your script, the bad indentation and poor names make it impossible for me to understand what you are trying to achieve. Please name your arrays to indicate what they contain, like @lines, @cats or @groceryList. And if you have to append numbers to the names of your variables, you are probably doing something wrong.

You do know that s/./ . /g means "replace every character by a space, a dot and a space" don't you?

You may want to read perlopentut, perlreftut and other tutorials.


In reply to Re: between pattern search not working by Eily
in thread between pattern search not working by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.