dhudnall has asked for the wisdom of the Perl Monks concerning the following question:
#!/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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: searching for multiple strings in a line
by toolic (Bishop) on Jul 10, 2007 at 16:14 UTC | |
by dhudnall (Novice) on Jul 10, 2007 at 17:14 UTC | |
by toolic (Bishop) on Jul 10, 2007 at 17:40 UTC | |
by dhudnall (Novice) on Jul 10, 2007 at 17:58 UTC | |
by roboticus (Chancellor) on Jul 11, 2007 at 10:34 UTC | |
|
Re: searching for multiple strings in a line
by swampyankee (Parson) on Jul 10, 2007 at 16:30 UTC | |
|
Re: searching for multiple strings in a line
by roboticus (Chancellor) on Jul 11, 2007 at 10:39 UTC | |
|
Re: searching for multiple strings in a line
by benmaynard (Initiate) on Jul 10, 2007 at 17:12 UTC |