This can be done with a simple substitution.
my $string = "abc|bcd|cde|";
$string =~ s/\|$//;
Вопрос
I need to trim the last part of the string here. The string i have is : abc|bcd|cde|
.
I need to get rid of the last |
... The trim()
command is not helping for some reason may be i am using it wrong, please help... thank you.
Решение
This can be done with a simple substitution.
my $string = "abc|bcd|cde|";
$string =~ s/\|$//;
Другие советы
Use chop:
my $string = "abc|bcd|cde|";
chop($string);
say $string;
output:
abc|bcd|cde
From the doc:
Chops off the last character of a string and returns the character chopped. It is much more efficient than s/.$//s because it neither scans nor copies the string. If VARIABLE is omitted, chops $_ . If VARIABLE is a hash, it chops the hash's values, but not its keys.