purplecat (
purplecat) wrote in
dw_dev_training2012-05-01 07:32 pm
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[site community profile]](https://www.dreamwidth.org/img/comm_staff.png)
Entry tags:
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.
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.
no subject
Also, the typical "error" result is undef. You can use 0 if it's relevant, but Perl typically uses undef as the "something went wrong" result.
no subject
no subject
If you want to test for a variable being undef, you can't do
if ( $var == undef )
or similar. You'd need to useif ( ! 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 :)no subject
if (! defined $var )
But if you're doing that, you should probably use unless.
no subject
no subject
no subject
The only exception to this is if you have a locally scoped closure (i.e., my $x = sub { ... };) then, since nobody else can call it except you, validating inputs is not something to worry about.
no subject