There is no such thing as the
null string. It is the
empty string. This is not just being pedantic. NULL has a number of other meanings, particularly in C (where it means '\0') and SQL (where is means "unknown value").
As for your question, I generally do:
sub function1 {
my ($arg1, $arg2) = @_;
$arg1 = "" unless defined $arg1;
}
If you're using 5.10 or higher, you can do:
sub function1 {
my ($arg1, $arg2) = @_;
$arg1 //= ""; # This is the new defined-or operator.
}
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?