in reply to between pattern search not working

What did you expect? Remove the strange substitution and your processing seems reasonable. (Your logic is unnecessarily complicated, but it seems to do what you ask.)
use strict; use warnings; #my @array1 = `cat $ARGV[0]`; #my @array2 = 'cat $ARGV[1]'; my @array1 = ("BIG_TREE\n"); my @array2 = ( ' DATA: CREATE TABLE TEMP.BIG_TREE ;', ':', ':', '-------', 'foo', ); my $read01 = 0; foreach my $i (@array1) { for (@array2) { chomp($i); $read01++ if $read01; #s/./ . /g; if ( /CREATE TABLE TEMP\.$i/ ) { $read01 = 1; } $read01 = 0 if (/^----/); next if ( $read01 == 1 ); next unless $read01; print "$_"; } }
OUTPUT:
::
Bill

Replies are listed 'Best First'.
Re^2: between pattern search not working
by Anonymous Monk on Jan 15, 2015 at 19:24 UTC
    hi how do I make the iterate over a array and then search for the string 1 first through one array2 (between two patterns) and then search for the same string 1 through array3 (between two string patterns) and print the array 1 output and array 2 output one below the other . I tried this but for some reason its iterating over the entire array 2 first for all the array 1 elements and then going through the array 3 for all the array 1 elements.
    my @array1 = `cat $ARGV[0]`; my @array2 = `cat $ARGV[1]`; my @array3 = `cat $ARGV[2]`; my $read01 = 0; my $newone = (); my $name = (); my $read01 = 0; foreach my $i (@array1){ my $j = $i; chomp($i); my $pp1 = () ; my $ff1 = (); my $gg1 = (); for(@array2){ $read01++ if $read01; s/CREATE TABLE/CREATE BREAKTABLES/g; my $read01 = 0; if ( "CREATE BREAKTABLES TEMP.$i") { ($pp1,$ff1) = split(/BREAKTABLES/); $ff1 =~ s/\(//g; $ff1 =~ s/\s+//g; $ff1 =~ s/TEMP\.//g; $name = $i if ($i = $ff1); ## print "name $name \n"; } print "$name $ff1 --- $_"; } #### END array2 my $read02 = 0; for(@array3){ chomp($i); $read02++ if $read02; s/CREATE TABLE/CREATE BREAKTABLES/g; if ( "CREATE BREAKTABLES TEMP.$i") { my ($pp1,$gg1) = split(/BREAKTABLES/); $gg1 =~ s/\(//g; $gg1 =~ s/\s+//g; $gg1 =~ s/TEMP\.//g; $newone = $i if ($i = $gg1); } print "MIRROR $newone $gg1 --- $_"; } }
    I am a non programmer and I having a hard time imagining. Thank you
      You are much more likely to get the answer that you seek if you follow the example of my previous reply. Provide a complete program (including data) so we all can run it and duplicate your problem. Show the output that it produces and the output that you want. Explain the difference. We do not care what indenting scheme you use, but please be consistent!
      Bill
        @array1='TABLE1','TABLE2'
        file1 data : CREATE TABLE TEMP.TABLE1 : : : ------- CREATE TABLE TEMP.TABLE2 : : : -------
        file2 data : CREATE TABLE TEMP.TABLE1 : : : ------- CREATE TABLE TEMP.TABLE2 : : : -------
        No I want the script to go through the tables in array1 and then through the file1 and file2 and pruduce the output like
        FILE1 : CREATE TABLE TEMP.TABLE1 : : : ------- FILE2 : CREATE TABLE TEMP.TABLE1 : : : ------- FILE1 : CREATE TABLE TEMP.TABLE2 : : : ------- FILE2 : CREATE TABLE TEMP.TABLE2 : : : -------
      @array1='TABLE1','TABLE2'
      file1 data : CREATE TABLE TEMP.TABLE1 : : : ------- CREATE TABLE TEMP.TABLE2 : : : -------
      file2 data : CREATE TABLE TEMP.TABLE1 : : : ------- CREATE TABLE TEMP.TABLE2 : : : -------
      No I want the script to go through the tables in array1 and then through the file1 and file2 and pruduce the output like
      FILE1 : CREATE TABLE TEMP.TABLE1 : : : ------- FILE2 : CREATE TABLE TEMP.TABLE1 : : : ------- FILE1 : CREATE TABLE TEMP.TABLE2 : : : ------- FILE2 : CREATE TABLE TEMP.TABLE2 : : : -------