what does undef means

can any one help me to know what does undef substitute for in the next fragment of code

sub delete_item
{
my ($dbh, $id) = @_;
    return ($dbh->do (qq{ DELETE FROM todo WHERE id = ? },
                undef,
                $id));
}
hatem_from_mesrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
perldoc -f undef
       undef EXPR
       undef   Undefines the value of EXPR, which must be an lvalue.  Use only
               on a scalar value, an array (using "@"), a hash (using "%"), a
               subroutine (using "&"), or a typeglob (using "*").  (Saying
               "undef $hash{$key}" will probably not do what you expect on
               most predefined variables or DBM list values, so don't do that;
               see delete.)  Always returns the undefined value.  You can omit
               the EXPR, in which case nothing is undefined, but you still get
               an undefined value that you could, for instance, return from a
               subroutine, assign to a variable or pass as a parameter.
               Examples:

                   undef $foo;
                   undef $bar{'blurfl'};      # Compare to: delete $bar{'blurfl'};
                   undef @ary;
                   undef %hash;
                   undef &mysub;
                   undef *xyz;       # destroys $xyz, @xyz, %xyz, &xyz, etc.
                   return (wantarray ? (undef, $errmsg) : undef) if $they_blew_it;
                   select undef, undef, undef, 0.25;
                   ($a, $b, undef, $c) = &foo;       # Ignore third value returned

               Note that this is a unary operator, not a list operator.
0
Suhas .QA ManagerCommented:
perldoc undef
http://perldoc.perl.org/functions/undef.html

In general, any value that is not defined is called as undef.

A good example:
http://www.linuxtopia.org/Perl_Programming/pickingUpPerl_29.html
0
Fairlight2cxCommented:
Everyone so far has defined what "undef" means/does for you.  I don't think that's your question.  You asked what it substitutes for.

The '?' in the do() function's first string is a placeholder.  Arguments coming after that initial string should be taken in order and put into the placeholders' places.

Seeing as there is only one placeholder, I believe the undef being present is an error.  There is one placeholder, and there are two substitution values present.  That's a mismatched count.  I believe undef and the following comma should be removed, thus allowing $id to take its apparently rightful place in the "id ="  WHERE clause in the SQL.

Technically, using a placeholder for one value is a complete waste.  I'd just rewrite it so that it was:  

return($dbh->do(qq(DELETE FROM todo WHERE id = $id)));

A placeholder in this instance is really just overhead you don't need to impart.  It's really meant for things like INSERT INTO tablename VALUES (?,?,?,?,?,?) situations where you have a cartload of extra values to pass in.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Adam314Commented:
From the DBI documentation for the do function:
    http://search.cpan.org/~timb/DBI-1.609/DBI.pm#do
The first parameter should be the SQL statement, the second any attributes for that statement, the third any bind values.

Your statement uses undef for the attributes, which means this statement should use the default attributes for the connection.  Some possible values for the attributes could be RaiseError or PrintError - so that this statement will behave differently than the default for the connection.

0
Fairlight2cxCommented:
Well that makes sense.  I usually don't use do() myself, preferring prepare/execute pairs.  Hence my newness to them.  But it does solve the apparent argument mismatch issue.

I still maintain that using placeholders for one value instead of doing it inline is simply greater overhead and complexity than necessary.
0
Adam314Commented:
>>I still maintain that using placeholders for one value instead of doing it inline is simply greater overhead and complexity than necessary.
Depends on what types of values $id can take.  If it could be a name, it gets complicated.  What if the name is "O'Mally" - it contains a single quote.  You now have to escape that.  Or, what if the $id comes from a user that entered it on a web form, and the user maliciously enters something like "1; DELETE FROM table;".  Using a placeholder will solve these problems - so the overhead may be very worthwhile.

The %attr parameter is available for prepare also, so that the particular statement can have attributes different from the connection default.  I don't use them very often either though.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.