in reply to between pattern search not working

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.

Replies are listed 'Best First'.
Re^2: between pattern search not working
by Anonymous Monk on Jan 15, 2015 at 12:39 UTC
    hi The search pattern is between the search string "BIG_TREE" which is part of the create statement and the "----"
    CREATE TABLE TEMP.BIG TREE : : ------ $i = "BIG_TREE" if ($_ =~ /CREATE TABLE TEMP.$i/){ $read01 = 1; } $read01 = 0 if (/^----/) ; next if ($read01 == 1); next unless $read01; print "$_";
    This part of the code is the problem