Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl中的索引和Rindex_Perl_Indexing - Fatal编程技术网

Perl中的索引和Rindex

Perl中的索引和Rindex,perl,indexing,Perl,Indexing,在编写perl脚本时,我混淆了Index和Rindex。在perl中Index和Rindex之间的区别是什么(用简单的例子解释)请向下评论Votes两者之间的区别是什么?这里我们必须声明substring?@user3098497在这两种情况下,您都在bar foo bar foo字符串中搜索substringfoorindex仅从字符串右侧开始搜索。您的意思是在reindex中我们必须声明substring.right? perl -E 'say rindex("bar foo bar foo

在编写perl脚本时,我混淆了Index和Rindex。在perl中Index和Rindex之间的区别是什么(用简单的例子解释)

请向下评论Votes两者之间的区别是什么?这里我们必须声明substring?@user3098497在这两种情况下,您都在
bar foo bar foo
字符串中搜索substring
foo
rindex
仅从字符串右侧开始搜索。您的意思是在
reindex
中我们必须声明substring.right?
perl -E 'say rindex("bar foo bar foo", "foo")'
                                 ^__ found first substring from right side
12

perl -E 'say index("bar foo bar foo", "foo")'
                        ^__ found first substring from left side
4