cens has asked for the wisdom of the Perl Monks concerning the following question:
{ 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:
At this point, I basically want to say$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; } }
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.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;}
Thanks a lot.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Look Ahead/Behind Via a File Handle
by Zaxo (Archbishop) on Aug 11, 2003 at 21:29 UTC | |
|
Re: Look Ahead/Behind Via a File Handle
by graff (Chancellor) on Aug 12, 2003 at 04:22 UTC | |
|
Re: Look Ahead/Behind Via a File Handle
by benn (Vicar) on Aug 11, 2003 at 23:32 UTC |