I think there is a way to do this, but I am having a hard time finding someone who as already asked this. Basically I have a huge SQL table schema, and I am trying to identify certian table the structure of the file looks like this:

{ TABLE "foo".bar row size = 50 number of columns = 5 index size = 25 +} create table "foo".bar ( var1 char(3) not null constraint "foo".n676_5452, var2 char(3) not null constraint "foo".n676_5453, var3 date not null constraint "foo".n676_5454, _rcd smallint default 0 not null ); revoke all on "foo".bar from "public";

What I want to do is to grab the name of the table (bar) and then look through the table declaration section to determine how many variables there are and which vars are in there. The problem is that I don't think I have the control over the file handle to walk back and forth through the file. This is what I have so far:

$file_name = @ARGV[0]; open (SCHEMA, $file_name); open (BIGLIST, ">>table_names.txt"); open (SMALLLIST, ">>refined_tbl_name.txt"); #open the file while(<SCHEMA>) { $line = $_; #is this a line that declares a new table? if ($line =~ /create table \".+?\"\.(.+?)$/mos) { #if so, print the name into a list print BIGLIST "$1 \n"; #create a new variable that has the name $table_nm = $1; } }
At this point, I basically want to say
while ($line ne ')') { $line_cnt++; if ($line =~ /$var_of_interest/) {$keep = 1}; } if ($line_cnt > $n and $keep == 1} then {$table_hash{$table_nm} = 1;}
However, this does not even come close to working very well. Because It can only work if $line is between the two parentheses. Is there a way to look ahead into the file? I can't figure it out, and the camel book is at home. Any pointers would be appreciated.

Thanks a lot.


In reply to Look Ahead/Behind Via a File Handle by cens

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.