in reply to split string and always get last word
But if not, a well-suited tool is the often-overlooked rindex:
Note that if the delimiter is not present, you'll get the whole string.my $str = '/alex/samsung/t2'; my $last_element = substr($str, rindex($str, '/') + 1); print "$last_element\n";
|
|---|