
d1zz13
User
Apr 24, 2007, 3:03 AM
Post #1 of 3
(2227 views)
|
|
Matching non word characters
|
Can't Post
|
|
I'm trying to validade some SQL but I'm having an issue matching non-word characters. I have a file that contains table names that I won't allow users to modify and I'm opening this and looping through each row. Here's what I have:
# Open the file containing the list of bad tables open(FH, "$tablelist") || die ("Unable to open $tablelist: $!\n"); @tables = <FH>; close(FH); # Open the script that's being checked open(FH, "$sqlfile") || die ("Unable to open $sqlfile: $!\n"); while ($l = <FH>){ chomp $l; # Check for any of the invalid tables foreach (@tables){ chomp; if ($l =~ /(insert\s+into|delete\s+from|update)\s+\Q$_\E\W/i){ print "\n$sqlfile failed integrity check, keyword matched at line $. ($_)\n\n"; exit(1); } } } print "\n$sqlfile passed integrity check\n"; close(FH); Lets assume my table file looks like this: If my code is like this then it seems to work fine
UPDATE object SET column1 = column2 but if it's like this, it doesn't
UPDATE object SET column1 = column2 so I assume that a newline character is not included as either a word character or a non-word character. I'm really stumped on this one. Any help would be appreciated. Regards Rich If it aint broke then don't try to fix it
|