This and other RFCs are available on the web at
  http://dev.perl.org/rfc/

=head1 TITLE

rindex and index should return undef on failure

=head1 VERSION

  Maintainer: Nathan Torkington <[EMAIL PROTECTED]>
  Date: Sep 12 2000
  Mailing List: [EMAIL PROTECTED]
  Number: 213
  Version: 1
  Status: Developing

=head1 ABSTRACT

index() and rindex() should return C<undef> if their
second argument is not a substring of their first
argument.

=head1 DESCRIPTION

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

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

This suggestion doesn't rely on RFC 53, "Built-ins: Merge and
generalize C<index> and C<rindex>", and works regardless
of whether 53 is accepted or not.

=head1 IMPLEMENTATION

The perl526 translator could turn index($a,$b) calls into

  do { my $tmp = index($a,$b); defined($tmp) ? $tmp : -1 }

=head1 REFERENCES

RFC 53: Built-ins: Merge and generalize C<index> and C<rindex>

perlfunc manpage for information on index() and rindex()

Reply via email to