In Perl, the reverse()
function is used to reverse a string.
scalar reverse(string)
This function takes the parameter, string
, which represents the string we want to reverse.
It returns a string in the reverse order of the values of string
, passed as a parameter to the reverse()
function.
# create strings @str1 = "osserpdE"; @str2 = "si"; @str3 = "!tseb eht"; # reverse strings @r1 = scalar reverse @str1; @r2 = scalar reverse @str2; @r3 = scalar reverse @str3; # print reversed strings. print "@r1\n"; print "@r2\n"; print "@r3\n";
@str1
, @str2
, and @str3
.reverse()
method to reverse the strings, and save the results.RELATED TAGS
CONTRIBUTOR
View all Courses