描述
此函数在列表context中以相反顺序返回LIST的元素。在标量context中,返回LIST值的串联字符串,所有字节的顺序相反。
语法
以下是此函数的简单语法-
reverse LIST
返回值
此函数在标量context中返回字符串,在列表context中返回列表。
例
以下是显示其基本用法的示例代码-
#!/usr/bin/perl -w
@array = (2,3,4,5,6,7);
print "Reversed Value is ", reverse(@array), "\n";
$string = "Hello World";
print "Reversed Value is ", scalar reverse("$string"), "\n";
执行上述代码后,将产生以下输出-
Reversed Value is 765432 Reversed Value is dlroW olleH