Hello, I am trying to write a small program/function that will isolate a string(s) in a sentence. What I am doing is I am parsing a file that contains a list of SQLs. The SQLs ofcourse contain a list of tables from which the SQL is either (updating, deleting, inserting into etc). What I want is to just isolate the table name in the SQL. The file contains ONE SQL per line. I am going to offer some really bad sample code to demonstrate how I would like this to work. I have tried countless solutions and haven't been able to get it to work yet. Please help if you can.
#The first thing I want to do is to be able to call the function from +the command line along with the name of the file to parse followed by + the keyword to isolate. $FileName=shift; $String=shift; #Then I would open the file to parse before going any further open(INFILE, $FileName) or die "Cant open the file\n"; #Then I think I should convert the file to a list to parse @file=<INFILE>; #Then I guess I would do something like the following #While reading in from the file while(<INFILE>) { #Save the contents of EACH line $TheLine = $_; #Then I would search through each element of the line foreach $x (@file) #or $TheLine { #Then I would check to see if the string entered on the command line e +xists in the line (which it always will because I will know which SQL +s e.g. delete, update, etc...I am searching for in the file) if(exists $TheLine{$String}) { #Then I want to delete (or replace) everything BEFORE the keyword $Str +ing with a blank.....basically meaning erase it. This is where I am a +bsolutely lost at because I don't know of a relatively easy way to do + this. I figured I would use the S// operator something like s/.*$String//g #Basically do something like that #This would leave only the String I was looking for FOLLOWED by the re +st of the line. }#end if

In reply to isolating strings 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.