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

check bind_columns for undefined values

by gropey (Initiate)
on May 17, 2011 at 15:58 UTC ( #905306=perlquestion: print w/ replies, xml ) Need Help??
gropey has asked for the wisdom of the Perl Monks concerning the following question:

How can you do

 @_ = map {defined($_) ? $_ : "null"} @_

when using $sth->bind_columns() ?

Comment on check bind_columns for undefined values
Download Code
Re: check bind_columns for undefined values
by ikegami (Pope) on May 17, 2011 at 18:31 UTC

    Your question isn't clear

Reaped: Re: check bind_columns for undefined values
by NodeReaper (Curate) on May 17, 2011 at 18:32 UTC
Re: check bind_columns for undefined values
by Neighbour (Friar) on May 18, 2011 at 08:56 UTC

    Why would you want to replace undef values (which correspond to NULL-values in the database) with the string "null" anyway? That can change the datatype of the column (since numeric columns can also contain NULL values, which you change to a text datatype).

    To answer your question, if you use

    $sth->bind_columns(\$var1, \$var2, \$var3);
    You'd have to check all vars to see if they're undef after fetching data and act accordingly.
    This method might make things simpler:
    @list_of_refs_to_vars_to_bind = (\$var1, \$var2, \$var3); $sth->bind_columns(@list_of_refs_to_vars_to_bind);
    Now you can use
    map { $$_ = "null" if (!defined $$_); } @list_of_refs_to_vars_to_bind;
    to do your evil thing.

      Hi, Thanks for the Map idea, I'm new to perl (but not other similar languages).
      Can someone explain why the example:

      map { $$_ = "null" if (!defined $$_); } @list_of_refs_to_vars_to_bind;

      ...uses $$_ when I would expect it to use $_ - i've googled round and round but haven't found an explanation yet.

      many thanks
      jonathan
        A decent tut on reference/dereference -- such as those found in Tutorials right here in the Monastery -- should make the answer clear.

        If you didn't program your executable by toggling in binary, it wasn't really programming!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (22)
As of 2015-07-02 18:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (44 votes), past polls