Hello, My problem that I have involves searching SQL statements to see if there is possibly a NESTED SQL statement within another statement. What I want my program to do is to be able to call the program and enter the file to be parsed along with a keyword (such as SELECT or DELETE). The program will open the file that will contain a list of SQL statements that I have pulled using grep. There will be one SQL statement per line. I already have that functionality in another program. What I NEED is to be able to call my program, give it the name of the SQL file containing the SQL statements, and enter a keyword (such as SELECT) and it either return a statement saying "Yes there is a nested SQL in this file" or "No the file is fine". The following code doesn't work but I quickly just jotted down some notes to give you an idea. Please help if you can. I ran the program below and it was stuck in a loop.
#!/usr/bin/perl use warnings; #use strict; #This is where we read in the arguments from the command line my $file_name = shift; my $String = shift; my $CharPos = 0; my $TheLine = 0; my $LineLen = 0; my $counter = 0; #my $nestedSelects = false; #This is where we read in the file and output to the file open(INFILE, $file_name) or die "Can't open file\n"; #while reading from the file... while(<INFILE>) { #make all lowercase characters uppercase tr/a-z/A-Z/; #Save the line's contents $TheLine = $_; #may need to convert the line to a list??? HERE #Gets the length of the line $LineLen = length($TheLine); #until we reach the end of the line until($CharPos == $LineLen) { while($counter!=2) { #for every element in the line foreach $x ($TheLine) { #if the string equals any of the eleme +nts in the line if($String eq $x) { #add one to the counter $counter++; }#end if }#end of the for statement #if two of the same words were found in the se +ntence (ne sted selects) if($counter >=2) { print "There is a nested SQL in this f +ile\n"; #nestedSelects = true; exit; }#end if else { $CharPos = $CharPos +1; } }#end of second while loop }#end of the until #sets the counter back to 0 for the next line $counter=0; }#end of the first while

In reply to searching for multiple strings in a line by dhudnall

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.