Liam Liam - 7 months ago 27
Perl Question

Performing a right trim against a string

I'm attempting to perform the equivalent of a simple right trim in Perl using a regex.

I have the value

'1445:'
assigned to the string
$test
, I'm attempting to trim the colon from the end.

I have the following code which attempts to trim the colon, with this code
$test
is still set to
'1445:'
however. Can anyone suggest what the issue is here?

my $test = '1445:';
$test =~ s/:$//;

Answer

That can't be the code you ran because it works.

$ perl -e'
    my $test = "1445:";
    $test =~ s/:$//;
    print "$test\n";
'
1445

Perhaps $test contained in the code you ran was different. Check with

use Data::Dumper;
local $Data::Dumper::Useqq = 1;
warn(Dumper($test));