http://qs321.pair.com?node_id=968564

Dandello has asked for the wisdom of the Perl Monks concerning the following question:

I've been working with someone else's code and came across this to generate a mySQL command:

 mysql_process( 0, 'do', qq~DELETE FROM `$db_table{$DBfile}[0]` WHERE `$db_table{$DBfile}[1]`="~ . join( '" OR `$db_table{$DBfile}[1]`="', @where ) . q~"~ );

Now, my gut tells me the section of code inside the join for the delimiter should be interpolated not a literal. But I'd like a second or third opinion.

Replies are listed 'Best First'.
Re: Join question
by JavaFan (Canon) on May 02, 2012 at 22:36 UTC
    Instead of asking our opinion, why don't you just print out the result of the concat and the join, and see whether it makes sense? And if it doesn't, see whether it makes sense when you interpolate it.

    I think that's much easier than posting a question ;-)

      It didn't make a lot of sense but it also seemed to be working in the application in a test setting.

Re: Join question
by sauoq (Abbot) on May 02, 2012 at 22:16 UTC
    Now, my gut tells me the section of code inside the join for the delimiter should be interpolated not a literal.

    It won't be interpolated. It is enclosed in single quotes.

    Update: Oh, I guess you are asking whether it was meant to be interpolated? Yes, I think that was the intent.

    -sauoq
    "My two cents aren't worth a dime.";
Re: Join question
by bobf (Monsignor) on May 03, 2012 at 01:58 UTC

    I would have expected it to be interpolated, but it is hard to say it is incorrect (especially if it was working in a test environment) without knowing what mysql_process does. Is there an eval in that routine?

      There's no eval in mysql_processes. I'm coming to the conclusion that the input to mysql_processes looks like it's working because @where is empty on the test app. I'll add more for it to work on tomorrow and see what happens - but I'm betting it should be interpolated.

      In the meantime, thanks everybody for looking at it and giving your input.

Re: Join question
by Dandello (Monk) on May 02, 2012 at 22:22 UTC

    I know it currently isn't being interpolated, but based on the rest of the code, I'm thinking it's wrong that it's written not to be interpolated. Does that make sense?

      Yes, I agree with you.

      I was updating my answer as you replied.

      -sauoq
      "My two cents aren't worth a dime.";

        Thank you - if it were my own code, I wouldn't need to ask as I would (hopefully) know what I was trying to do. VBG