Hm. I'm not sure I'd call having to wrap every use of substr in a no warnings block, more perlish. I'd just go with '' and have done with it.
It just strikes me that as substr is a built-in, it could accept undef as a legitimate parameter.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
| [reply] [d/l] |
It seems to me that there is a considerable difference between using a variable who current value is undef, and using undef explicitly.
And that, at least for built-ins that have (or could have) access to the information to know the difference, they could (and should?) be treated differently.
If I pass a varible who's current value is undef, there is a possibility that it is an accident of bad flow control. If I pass undef explicitly, I've chosen to do so.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
$x = 3 + undef;
printf "%s", undef;
undef =~ /./;
The warning is to catch cases like:
$x = expression unexpectedly returning undef.
substr $y, 1, 2, $x;
One could argue that using a literal undef shouldn't trigger the warning (after all, then the programmer is explicit), but I don't think that information is easily available at the moment the warning is triggered. And the programmer may as well write "" or 0 anyway, saving some keystrokes. | [reply] [d/l] [select] |
use warnings;
no warnings 'uninitialized';
In this particular case though using '' seems cleaner.
Jenda
Enoch was right!
Enjoy the last years of Rome.
| [reply] [d/l] |