Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

uninitialized value in join or string

by Win (Novice)
on Oct 31, 2005 at 09:39 UTC ( #504201=perlquestion: print w/replies, xml ) Need Help??

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

Please could somebody enlighten me on the ins and outs of the following error message.
Use of uninitialized value in join or string at C:/Perl_activate/20_Oc +tober_2005_L.pl line 438, <FLAT_FILE> line 1191.
in relation to the following code.
my $sth_C = $dbh->prepare($Return_results) or die "Couldn't prepar +e query: ".$dbh->errstr; $sth_C->execute() or die "Couldn't execute query: ".$sth_C->errstr +; while (my @row = $sth_C->fetchrow_array) { print OUTPUT_FILE join("\t", @row); ###<< The error message app +lies to this line of code. print OUTPUT_FILE "\n"; undef @row;

Replies are listed 'Best First'.
Re: uninitialized value in join or string
by EvanCarroll (Chaplain) on Oct 31, 2005 at 09:46 UTC
    Observe:
    perl -we'print join ",", @{[undef]}' Use of uninitialized value in join or string at -e line 1.
    One of the values in your row, (columns returned from sql row) is NULL in sql, meaning undef in perl. Add to your sql statement, where not null or if your using Oracle employ nvl(), if postgres see coalesce().


    Evan Carroll
    www.EvanCarroll.com
      Nice one-liner there. It may just be better if I replaced NULLs with ' 's (ie. spaces). Actually I don't know whether these NULL values are slowing my program down or not. I may just ignore the error message and not do anything about it. However, I am willing to take advice on that. There are problems with using WHERE NOT NULL as some of the values in the array are not NULL and these are required.
        You could always map over the array and set the undef values to '', I would personally suggest keeping the database pristine. I would use nulls if it increases data clarity for a more ugly solution in the perl base. '' would violate a unique constraint where as multiple nulls woulden't for instance. Nulls are also open to the database implimentation, and can be optimized away very easily, an empty string however is kept as just as that, rather than a small pointer to null.

        Update:
        or a simple join ",", grep defined, @row;


        Evan Carroll
        www.EvanCarroll.com
Re: uninitialized value in join or string
by jesuashok (Curate) on Oct 31, 2005 at 09:54 UTC
    Hi

    To enlighten you more on the same error when you enable perl warnings , diagnostics or strict then you will get this message when you try to run the code. this is because the undef value assigned to some Variable used in perl code.

    "Keep pouring your ideas"

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2022-01-27 12:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (70 votes). Check out past polls.

    Notices?