in reply to Re: DBI execute() args in array format (or similar) possible?
in thread DBI execute() args in array format (or similar) possible?

The magic line of code that solved my problem...   $STH->execute(eval{join(',',@args),return(@args)});
Say what? That's equivalent to writing   $STH->execute(@args); The result of the join() is discarded.

I rather think something else is going one.

Replies are listed 'Best First'.
Re: Re: Re: DBI execute() args in array format (or similar) possible?
by snafu (Chaplain) on Aug 13, 2002 at 03:53 UTC
    It can't be the same because the script didn't work with execute(@args) but it does work with

    execute(eval{join(',',@args),return(@args)});
    *shrug* I don't know why...it just does.

    One possible explanation is that the execute method is looking for separate arguments and not a list. Thus, I am taking a list and turning it into arguments.

    summary of what I think is happening: The execute() method wants distinct arguments ie
    execute(arg1,arg2,arg3) vs execute(qw(arg1 arg2 arg3)) which is the same, of course, as execute(@args). The latter 2 examples don't work possibly because its a list instead of separate and distinct scalars respective to the number of place holders in the prepare() statement.

    Does execute() not work this way?

    Updated: Fixed syntax mistake with qw().

    _ _ _ _ _ _ _ _ _ _
    - Jim
    Insert clever comment here...

      Brother snafu, I fear you have stumbled onto a series of incantions that appear to work, but that you still do not understand the underlying problem. Consider:   eval {join(',', @args), return(@args)} has the same affect as   eval {return(@args)} since the join() has no side-effect. In turn, these have the same effect as     eval {@args} and   @args

      The execute() method wants distinct arguments ie execute(arg1,arg2,arg3) vs execute(qw(arg1,arg2,arg3)) which is the same, of course, as execute(@args).

      if @args hold (1,2,3), then

      • execute(1,2,3);
      • execute(qw(1 2 3));
      • execute(@args)
      are equivalent, but
      • execute(qw(1,2,3));
      is not equivalent, since qw(1,2,3) is an list that contains a single element. It's the whitespace that's significant in qw(), not the commas.

        Oops! Don't you hate it when you put something in your writeup that is a typo? Note the change I made to my post prior to your reply. I fixed my typo.

        Now, I absolutely agree with your statements. This is why I am so baffled by the situation and get this...it works now using the simple execute(@args) but I swear on everything I know that I did *not* make any changes to the code with the exception of changing to '@args' from the join() statement. However, that works now. It is all very strange and indeed I bet that I will stumble across this little phenomenon again somewhere. Maybe it was the command line args I was using *shrug*. If you read my other posts you will see that @args was most certainly giving off the correct number of elements (I pasted a few outputs where I was trying to show that...they are numbered elements).

        Anyway, I sincerely appreciate all of your comments.

        _ _ _ _ _ _ _ _ _ _
        - Jim
        Insert clever comment here...