Peter,
Quoting Peter R. Wood (Lists) <[EMAIL PROTECTED]> [19 Feb-02 16:15]:
> I am still fairly a newbie with Perl regexes. So today was a
> momentous occasion that I wrote a regex without looking at a
> book, manual, or example, and had it work on the first try!
Nice.
> The regex is designed to look at an oracle/sql query, determine
> if there is a hint included, and then extract the hint.
> Generally hints look like this:
>
> /*+ FIRST_ROWS DOMAIN_INDEX_SORT */
>
> So here is my regex:
>
> if ($query =~ /\/\*\+\s+(.*)\s+\*\//) {
> $hint = $1;
> }
Make it easy on yourself: use a delimiter other than /; I'm using
',' below, since it doesn't appear in your regex. Also, use the
/x modifier to make it commentable:
# Your regex: \/\*\+\s+(.*)\s+\*\/
if ($query =~ m,
/\*\+ # Opening, looks like /*+
\s+ # some whitespace
(.*)
\s+ # some whitespace
\*/ # Closing, looks like */
,x) {
$hint = $1;
}
Not using / avoid toothpick syndrome, and spacing it out makes it
much easier to read.
You might want to use .+ rather than .* in the middle; .* will
match 0 or more characters, which means that the empty string
also matches (although in boolean context it returns false, so
the if() clause doesn't get executed).
Judging from your description of the hint, I assume that you are
later splitting $hint into FIRST_ROWS and DOMAIN_INDEX_SORT
pieces; why not do it here:
if ($query =~ m,
/\*\+ # Opening, looks like /*+
\s+ # some whitespace
(.+) # FIRST_ROWS
\s+ # some whitespace
(.+) # DOMAIN_INDEX_SORT
\s+ # some whitespace
\*/ # Closing, looks like */
,x) {
$hints{$1} = $2; # Or whatever
}
(darren)
--
Don't sweat the petty things, and don't pet the sweaty things.