in reply to append return if defined else not
In the interest of keep the code clear and short, my answer depends on what false values return1 could return. The subject seems to indicate you only want to check for undefined, so the second and third solution would be appropriate. (The first would work, but it would also issue a warning.)
If the false values return1 can return are empty strings:
my $val = return1() . return2();
If the false values return1 can return are undef and/or empty strings:
my $val = return1(); $val .= return2();
If the false values return1 can return are undef and/or empty strings:
my $val = (return1() // '') . return2(); # 5.10+
If return1 can return zero, then you have a weird function.
|
|---|