We help IT Professionals succeed at work.
Get Started

Complicated pattern-matching in Perl

Bidan Zhu
Bidan Zhu asked
Last Modified: 2008-09-17

I am currently upgrading a huge ColdFusion5 project (over 1000 ColdFusion pages) to ColdFusion8, and have the following problem:
In ColdFusion5, you can specify a query like:

<CFQUERY Name="query1" DataSource="ds">
    select *
      from test
     where name="something"
       and type="test"

Double-quoted SQL strings are allowed in CF5.

But in ColdFusion8, only single quoted SQL strings are accepted, so the above must be changed to:

<CFQUERY Name="query1" DataSource="ds">
    select *
      from test
     where name='something'
       and type='test'

I want to use a perl script to run through all the files to find out where double-quoted strings are used in <cfquery> tag, but this is trickier than I thought because there might be other tags nested in <cfquery>...</cfquery> such as <cfif>, which might legitimately have double-quoted strings as attributes, such as:

<CFQUERY Name="query1" DataSource="ds">
    select *
      from test
     where name='something'
     <cfif typeIsSet = "true">
       and type='test'

Cases like this should NOT strike an alarm.

So, in English, I want to find out if there are double-quoted strings used within <cfquery> tags, which are NOT attributes of another tag.

Could some Perl Regexp guru give me a hand here?
Watch Question
Most Valuable Expert 2014
Top Expert 2015
This problem has been solved!
Unlock 1 Answer and 13 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE