B
Bill
#!/usr/local/bin/perl
# try.pl
use strict;
my $string = 'ABC';
my $substr = '';
my $rval = index($string,$substr);
print "-> $rval\n";
__END__
$ try.pl
-> 0
Why does this happen? It seems that index() should return -1.
$ perldoc -f index
index STR,SUBSTR,POSITION
index STR,SUBSTR
The index function searches for one string within
another, but without the wildcard-like behavior of a
full regular-expression pattern match. It returns
the position of the first occurrence of SUBSTR in
STR at or after POSITION. If POSITION is omitted,
starts searching from the beginning of the string.
The return value is based at "0" (or whatever you've
set the "$[" variable to--but don't do that). If
the substring is not found, returns one less than
the base, ordinarily "-1".
# try.pl
use strict;
my $string = 'ABC';
my $substr = '';
my $rval = index($string,$substr);
print "-> $rval\n";
__END__
$ try.pl
-> 0
Why does this happen? It seems that index() should return -1.
$ perldoc -f index
index STR,SUBSTR,POSITION
index STR,SUBSTR
The index function searches for one string within
another, but without the wildcard-like behavior of a
full regular-expression pattern match. It returns
the position of the first occurrence of SUBSTR in
STR at or after POSITION. If POSITION is omitted,
starts searching from the beginning of the string.
The return value is based at "0" (or whatever you've
set the "$[" variable to--but don't do that). If
the substring is not found, returns one less than
the base, ordinarily "-1".