>>>>> "PRL" == Perl6 RFC Librarian <[EMAIL PROTECTED]> writes:

PRL> In perl5, index() and rindex() return -1 if the
PRL> substring isn't found.  This seems out of step with
PRL> the rest of Perl's functions, which return C<undef>
PRL> on error.  I propose changing index() and rindex()
PRL> to return C<undef> if the substring isn't found.

PRL> This would also cause warnings to be issued when
PRL> programmers use the results of index() or rindex()
PRL> assuming the substring was found.

Removing -1 as a valid result, could be a breakage (if someone is
doing something weird with a negative result)

Would it be reasonable to ask that passing undef into the offset
or start of substr have substr return an undef?

This would break the undef == 0 under normal circumstance, but
it would prevent an error from propogating.

        $foo = "flabergasted";
        substr($foo, index($foo, 'abc'), 20);   # Returns undef

If this is too much breakage what about only if it is the argument?

        $foo = "flabergasted";
        $x = index($foo, 'abc');
        substr($foo, $x, 20);           # starts from the end

<chaim>
-- 
Chaim Frenkel                                        Nonlinear Knowledge, Inc.
[EMAIL PROTECTED]                                               +1-718-236-0183

Reply via email to