purplecat: Hand Drawn picture of a Toy Cat (Default)
purplecat ([personal profile] purplecat) wrote in [site community profile] dw_dev_training2012-05-01 07:32 pm

Can a journal entry id be 0?

For Bug 2152 I've found I need to create a subroutine that checks whether a form element refers to a valid entry in the user's journal separately from the various subroutines for actually saving it as a sticky.

If a journal entry id can never be zero then this subroutine could return the id number if it is valid and 0 otherwise. In that case the subroutine can replace duplicate code in at least two places, but obviously if an entry can be 0 then the subroutine had better just return 0 or 1.
sophie: A cartoon-like representation of a girl standing on a hill, with brown hair, blue eyes, a flowery top, and blue skirt. ☀ (Default)

[personal profile] sophie 2012-05-01 07:03 pm (UTC)(link)
BTW, you may already know this, but this bit me the first time I used undef, so I'll leave this here in case you or anybody else watching runs into it...

If you want to test for a variable being undef, you can't do if ( $var == undef ) or similar. You'd need to use if ( ! defined( $var ) ). That's because undef isn't actually a value you can compare against. Rather annoying, but there you go. Hopefully this staves off any confusion in this regard :)
mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)

[staff profile] mark 2012-05-01 07:05 pm (UTC)(link)
Style note: minimize extraneous paranthesis. Prefer this format:

if (! defined $var )

But if you're doing that, you should probably use unless.