I think, I have found a work around for this. After looking at here I found that SQL::Tokenizer was suitable for my case and used regex used by the Tokenizer module to sanitize my query. It needs a little working on but, for now works for most of my test cases.

use strict; my $insane_sql = shift or die "usage sanitize_sql_query.pl <insane que +ry>"; print "\n\n$insane_sql\n\n"; my $sane_sql = ""; #Match anything inside single quotes. #Got it from SQL::Tokenizer. #Author:Igor Sutton Lopes while ($insane_sql =~ m/'.*?(?:(?:''){1,}'|(?<!['\\])'(?!')|\\'{2})/sm +xg) { my $pre_match = $`; my $match = $&; my $post_match = $'; print "Match: $match\n"; $match =~ s/'//g; #replace the single quotes $match =~ s/\W/_/g; #sanitize the match $insane_sql = $pre_match . $match . $post_match; } print "\n\n$insane_sql\n\n"; __END__ perl sanitize_sql_query.pl "SELECT TO_DATE(['(PDH-CSV 4.0) (Central St +andard Time)(360)']) AS CAPTUREDATE, AVG(TO_REAL(['\\Server\LogicalDi +sk(N:)\Avg. Disk sec/Read'])) AS AVG_LOG_SEC_READ FROM 'C:\PerfCSV\Se +rver_01200549.csv' GROUP BY TO_DATE(['(PDH-CSV 4.0) (Central Standard + Time)(360)'])" SELECT TO_DATE(['(PDH-CSV 4.0) (Central Standard Time)(360)']) AS CAPT +UREDATE, AVG(TO_REAL(['\\Server\LogicalDisk(N:)\Avg. Disk sec/Read']) +) AS AVG_LOG_SEC_READ FROM 'C:\PerfCSV\Server_01200549.csv' GROUP BY +TO_DATE(['(PDH-CSV 4.0) (Central Standard Time)(360)']) Match: '(PDH-CSV 4.0) (Central Standard Time)(360)' Match: '\\Server\LogicalDisk(N:)\Avg. Disk sec/Read' Match: 'C:\PerfCSV\Server_01200549.csv' Match: '(PDH-CSV 4.0) (Central Standard Time)(360)' SELECT TO_DATE([_PDH_CSV_4_0_Central_Standard_Time_360_]) AS CAPTUREDA +TE, AVG(TO_REAL([_Server_LogicalDisk_N_Avg_Disk_sec_Read])) AS AVG_LO +G_SEC_READFROM C_PerfCSV_Server_01200549_csv GROUP BY TO_DATE([_PDH_C +SV_4_0_Central_Standard_Time_360_])
Edit: $match =~ s/\W+/_/g;, this should have actually been $match =~ s/\W/_/g; since we need all special characters to be converted to an underscore.
Hope is a Heuristic Search.

In reply to Re: Perfmon log parser. Problem with column names having special chars. by hemanth.damecharla
in thread Perfmon log parser. Problem with column names having special chars. by hemanth.damecharla

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.