>>>>> "JP" == John Porter <[EMAIL PROTECTED]> writes:
JP> Chaim Frenkel wrote:
>>
>> Removing -1 as a valid result, could be a breakage (if someone is
>> doing something weird with a negative result)
JP> What, like using it as an index into a substr?
JP> Bad Code is its own reward, my friend.
Is that a for or an against.
>> $foo = "flabergasted";
>> substr($foo, index($foo, 'abc'), 20); # Returns undef
JP> One should never do this, regardless of what index() returns on
JP> failure. Now, if index() threw an exception on failture, you'd
JP> be o.k. But I don't think we want that...
I do this _all_ the time. (Well in my SQL.) The correct translation
for untranslatable items is NULL (or undef in perl-speak). Yes,
sometimes it isn't, for those extra coding is required.
Having substr (or other functions) generate an undef is a quite
reasonable way to handle this scenerio. This isn't any different
than $bar = $hash{$foo} wher $foo doesn't exist.
If you must have a value, then check for it. If an undef is acceptable
then check for that.
I would find checking the final result somehow much clearer to read.
<chaim>
--
Chaim Frenkel Nonlinear Knowledge, Inc.
[EMAIL PROTECTED] +1-718-236-0183