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 = ? },
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Fairlight2cxConnect With a Mentor Commented:
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.
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.

                   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.
Suhas .QA ManagerCommented:
perldoc undef

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

A good example:
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Adam314Connect With a Mentor Commented:
From the DBI documentation for the do function:
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.

Fairlight2cxConnect With a Mentor Commented:
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.
Adam314Connect With a Mentor Commented:
>>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.
All Courses

From novice to tech pro — start learning today.