Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: (dkubb) Re: (2) A Little review for a little DBI and CGI?

by coolmichael (Deacon)
on Mar 28, 2001 at 13:38 UTC ( #67785=note: print w/ replies, xml ) Need Help??


in reply to (dkubb) Re: (2) A Little review for a little DBI and CGI?
in thread A Little review for a little DBI and CGI?

I am thrilled to have so many comments. Thank you dkubb.

I've got taint checking on now, and I use $q=CGI->new. Eventually, I want to write a function that dies gracefully, printing an error to the web browser before it dies. I don't think I want to use CGI::Carp "fatalsToBrowser" as that gives too much information to the nasty people that might be using the stuff. I've changed the sql statement and untainted $criteria, so it has to be only letters and numbers. It was a bit of a pain getting the place holder to work, but eventually...

I don't take such a long critique personally. I'm quite happy to recieve positive and constructive comments. Thank you again.

Unfortunatly, now that it's working so well, I've discovered a bug and need some help. The data is comming from a paradox database. Paradox is able to export it to CSV but isn't smart enough to escape the quote in the titles. I've been looking for a regex on the monastery to add escapes, but haven't found one yet. Do you have any suggestions?


Comment on Re: (dkubb) Re: (2) A Little review for a little DBI and CGI?
Select or Download Code
Re: Re: (dkubb) Re: (2) A Little review for a little DBI and CGI?
by marius (Hermit) on Mar 28, 2001 at 22:00 UTC
    coolmichael,
    Add escapes? quotemeta() is your friend.

    -marius
(tye)Re3: A Little review for a little DBI and CGI?
by tye (Cardinal) on Mar 28, 2001 at 23:01 UTC

    Ugh. What if you have a title of 'Why "foo", "bar", and "baz"?' and it gets written to a CSV file as: ...,16,"Why "foo", "bar", and "baz"?",20,...
    then how do you expect to be able to tell which "s need to be escaped??

    Well, I'll try me best... Let's assume that no title contains a string matching /",\S/ and that there is never whitespace after a comma in your CSV file.

    s{ \G( [^",]+ | "(.*?)" )(,(?=\S)|$) }{ if( ! $2 ) { $1.$3; } else { my $f= $2; $f =~ s/"/""/g; '"'.$f.'"'.$2; } }gx;

    If you do have whitespace after commas, then an alternate solution would be to assume that all titles that contain "s always contain an even number of quotes and that the first character after the first quote of a pair isn't a comma:

    s{ \G( [^",]+ | "((?: [^"]+ | "" | "[^",][^"]*" ))*" )(,|$) }{ if( ! $2 ) { $1.$3; } else { my $f= $2; $f =~ s/"/""/g; '"'.$f.'"'.$2; } }gx;
    I hope one of those helps. (Sorry, they aren't tested. Just tell me which one matches your situation and I'll be happy to help if there are bugs.)

            - tye (but my friends call me "Tye")
      Unfortunatly, neither situation applies. Some of the titles have only one quote in them, some have three or four. Some of the quotes have commas after them. The solution I've decided to go with is editing the paradox database to get rid of the commas. Find and Replace, yeah, baby, yeah. Groovy.

      I think it'll be the only reliable way to do it, and it'll probably fix some of the errors the database has been having.

      /me crosses his fingers.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://67785]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2014-12-22 08:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (112 votes), past polls