Ok, there's a few points I'd like to make.

read: perldoc perlvar  AND perldoc perlsub

before continuing ;)





















#1 local() is for perl's Variables, my() is for your variables.

#2 an array in scalar context evaluates to the number of elements in the
list, hence the 1.

I believe what you're looking for is something like this:

sub dbQuery {
        my $query = shift;  # shifts from the beginning of @_ if no
                                                # other array is provided.
        # do stuff with query;
}

OR

sub dbQuery {
        my ($query) = @_;
        # do stuff with query;
}

In the second example, the () introduces list context to the left side of
the operand, which then causes @_ to be evaluated as you expected.  It
seems like an annoyance, but context is one of perl's most powerful
features as its more like natural language.

Enjoy,

On Tue, Apr 13, 2004 at 02:25:32PM -0500, J. Alejandro Ceballos Z. wrote:
> 
> I've created a subrutine to acces DB, but while sending the Query it get an 
> error.
> 
> My function looks like:
> 
> sub DbSqlQuery
>   {
>   local $str_query = @_ if @_;
>   print $str_query;
>   <... blah, blah ..>
>   }
> 
> And my program call it like:
> 
> <... blah, blah ..>
> $str_Query = "SELECT admin_ID, admin_name FROM admins WHERE (admin_login = 
> '$str_Login');
> print "Content-type: text/plain\n\n TEST: $str_Query :: \n";
> &DbSqlQuery($str_Query);
> <... blah, blah ..>
> 
> 
> When I run, I get the following output:
> 
> SELECT admin_ID, admin_name FROM admins WHERE (admin_login = 'my value') :: 
> 1
>  ERROR: 1
>       1064 (You have an error in your SQL syntax near '1 ' at line 1)
> 
> 
> 
> 
> Where it comes the '1'?
> 
> I must use pointers or similar?
> 
> 
> 
> -- 
> 
> 
> saludos,
> 
> 
>      J. Alejandro Ceballos Z.   |
>      ---------------------------+---------------------------
>  http://alejandro.ceballos.info |
>   [EMAIL PROTECTED] |  "Las batallas contra las mujeres
>  -------------------------------+  son las ?nicas que se ganan huyendo".
>                                 |
>                                 |          -- Napoleon Bonaparte.
> 
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 

-- 
Brad Lhotsky <[EMAIL PROTECTED]>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to